This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
built_in:app_events [2014/10/08 17:07] stevegarman |
built_in:app_events [2018/12/30 13:31] (current) |
||
---|---|---|---|
Line 3: | Line 3: | ||
They are | They are | ||
- | ^Function ^Called when ^ | + | ^ Function |
- | |OnStart()|application is created | | + | | OnStart() |
- | |OnMenu( name ) |user selects a menu item | | + | | OnMenu( name ) | user selects a menu item | |
- | |OnBack() |the back key is pressed but only if it follows app.EnableBackKey( false ); | | + | | OnBack() |
- | |OnPause()|application is paused. (eg. When user switches to home screen)| | + | | OnPause() |
- | |OnResume() |application is resumed. (eg. When user returns from home screen) | | + | | OnResume() |
- | |OnConfig() |configuration changes. (eg. When user rotates phone) | | + | | OnConfig() |
- | |OnAlarm() |an alarm previously set by app.SetAlarm() is triggered | | + | | OnAlarm() |
+ | | OnData() | ||
- | The code of the sample that is bundled with AndroidScript | + | The code of the sample that is bundled with DroidScript |
<code javascript appEvents.js> | <code javascript appEvents.js> | ||
//Called when application is created. | //Called when application is created. | ||
Line 20: | Line 21: | ||
app.SetMenu( " | app.SetMenu( " | ||
app.EnableBackKey( false ); | app.EnableBackKey( false ); | ||
- | } | + | |
+ | | ||
+ | | ||
+ | | ||
+ | | ||
//Called when user selects a menu item. | //Called when user selects a menu item. | ||
Line 54: | Line 59: | ||
{ | { | ||
app.ShowPopup( " | app.ShowPopup( " | ||
+ | } | ||
+ | |||
+ | // | ||
+ | // | ||
+ | function OnAlarm( id ) | ||
+ | { | ||
+ | app.ShowPopup( " | ||
+ | } | ||
+ | |||
+ | //Handle data sent from other apps. | ||
+ | function OnData( isStartUp ) | ||
+ | { | ||
+ | | ||
+ | var intent = app.GetIntent(); | ||
+ | if( intent ) | ||
+ | { | ||
+ | //Extract main data. | ||
+ | var s = " | ||
+ | s += "type: " + intent.type + " | ||
+ | s += "data: " + intent.data + " | ||
+ | | ||
+ | //Extract extras. | ||
+ | s += " | ||
+ | for( var key in intent.extras ) | ||
+ | s += key+": " | ||
+ | | ||
+ | app.Alert( s, " | ||
+ | } | ||
+ | } | ||
+ | |||
+ | </ | ||
+ | |||
+ | =====OnConfig===== | ||
+ | The following code can be useful if you want to change the layout in the OnConfig event. | ||
+ | |||
+ | <code javascript> | ||
+ | //Called when application is started. | ||
+ | function OnStart() | ||
+ | { | ||
+ | //Create a layout with objects vertically centered. | ||
+ | lay = app.CreateLayout( " | ||
+ | var test = app.GetOrientation(); | ||
+ | var hv = " | ||
+ | if( test==" | ||
+ | lay.SetOrientation( hv ); | ||
+ | |||
+ | txt = app.CreateText( "Hello " ); | ||
+ | txt.SetTextSize( 64); | ||
+ | lay.AddChild( txt ); | ||
+ | |||
+ | txt1 = app.CreateText( " | ||
+ | txt1.SetTextSize( 64 ); | ||
+ | lay.AddChild( txt1 ); | ||
+ | app.AddLayout( lay ); | ||
+ | } | ||
+ | //Called when screen rotates | ||
+ | function OnConfig() | ||
+ | { | ||
+ | var test = app.GetOrientation(); | ||
+ | var hv = " | ||
+ | if( test==" | ||
+ | lay.SetOrientation( hv ); | ||
} | } | ||
</ | </ |