> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dairy.foundation/llms.txt
> Use this file to discover all available pages before exploring further.

# AppHooks

The SDK comes built in with the following AppHooks:

`@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, `Feature`s from `Core` and `Subsystem`s
from `Mercurial` are similar to AppHooks!

To be honest, the best introduction to the apphooks is in the overviews:

[Java](https://github.com/Dairy-Foundation/Dairy/tree/master/TeamCode/src/main/java/org/firstinspires/ftc/teamcode/examples/apphooks/JavaOverview.java)

[Kotlin](https://github.com/Dairy-Foundation/Dairy/tree/master/TeamCode/src/main/kotlin/org/firstinspires/ftc/teamcode/examples/apphooks/KotlinOverview.kt)

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 or
  `object` class in Kotlin. This is because `Sinister` scans for static
  instances, the Kotlin `object` class 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's `OnCreate` apphooks, if you use the sdk one, this is not guaranteed).
