@OnCreate -> called early into the app’s boot up
@OnCreateEventLoop -> called after OnCreate, when the FTC EventLoop is created
@OnCreateMenu -> called when the menu on the robot controller gui is created
@OnDestroy -> called when the app is shutting down
@OpModeRegistrar -> called when opmodes are registered
@WebHandlerRegistrar -> called when the webserver is made
These apphooks are how things like dashboard automatically start up and add
opmodes, and allow you to gain access to opmode runtime internal data
structures.
These apphooks are annotations, that must be applied to a public static
method with specific parameters.
Dairy provides its own AppHooks, that take the form of interfaces, and are
called on static instances of the interface.
This is better suited to the general Dairy philosophy, and is more type safe.
It also means that its easy to for you to write your own AppHooks, if you’re
developing a library. For instance, Features from Core and Subsystems
from Mercurial are similar to AppHooks!
To be honest, the best introduction to the apphooks is in the overviews:
Java
Kotlin
It showcases all the interfaces, and how to use them.
Additional notes:
- You don’t need to implement all the interfaces, just the ones you want to use.
- You need the
public static DataType INSTANCE = new DataType();Java orobjectclass in Kotlin. This is becauseSinisterscans for static instances, the Kotlinobjectclass compiles out to this Java code, and is like a singleton. Without it, the hooks won’t get run. - If you’re using Dairy, you should use the Sinister hooks where possible, as
they ensure than any extra behaviour that Dairy requires will be run first.
(i.e. Sinister runs in
OnCreate, but ensures that it runs before any of Dairy’sOnCreateapphooks, if you use the sdk one, this is not guaranteed).