In your app you can use various event functions which will be automatically called by DroidScript.

OnStart()

This is probably the most popular one. It will be called when DroidScript has initialized and it is the last function which will be called from global scope. That means every timeout you might have set will be called after OnStart was called.
When OnStart has returned, the apps 'started' state will be set to true. Therefore app.IsStarted() method will return true as well.

Example - OnStart click to expand contents 

OnMenu(name)

This event is called when the user selects an item from the in-app menu.
See Also: SetMenu, ShowMenu

Example - OnMenu click to expand contents 

OnBack()

By default the app closes if the user presses the devices back-button. However, you can disable that behaviour by calling app.EnableBackKey(false).
In this case the OnBack event will be called instead of closing the app. This can be useful to create a confirmation dialog before exiting:

Example - Confirm Exit click to expand contents 

OnPause()

The OnPause event will be called when the user sends the app to the background, ie. when pressing the home button.

Example - Detect Pause click to expand contents 

OnResume()

The OnResume event will be called when the user returns to your app after sending it to the background.

Example - Detect Resume click to expand contents 

OnConfig()

OnConfig is called when a device configuration changes, especially the screen orientation. This can be used to rearrange your layouts on orientation change.

Example - Layout Orientation click to expand contents 

OnAlarm()

If you have set up an app Alarm and it is triggered it will call the OnAlarm event.

Example - OnAlarm click to expand contents 

OnData()

When an other app has sent an intent to your app you will get notified by the OnData event. Then you can retrieve the intent object using the app.GetIntent() method.

Example - Received Intent Data click to expand contents 

OnDrawer(side, state)

When the user opens or closes a drawer the OnDrawer callback is called.
state can be “Open” or “Closed”
side can be “Left” or “Right”