User Tools

Site Tools


Sidebar

Privacy Policy

News

Version 2.50 is out since Jan 1st 2022


Frequently Asked Questions


Namespaces

Note for contributors

If you wish to create a new page in the DroidScript wiki, please click on the most appropriate namespace above and follow the notes for contributors there.

Because of spam, it has been necessary to add a CAPTCHA to the registration form and the save option for editing pages. You will not need to prove you are human if you are logged in, so please register.

Please feel free to improve any existing page, as well as adding new pages to increase the sum of public knowledge about DroidScript.

Formatting Syntax

built_in:app_events

This is an old revision of the document!


appEvents.js
//Called when application is created.
function OnStart()
{       
	app.ShowPopup( "OnStart" );
	app.SetMenu( "MyMenu1,MyMenu2" );
	app.EnableBackKey( false );
 
        //Get current time in milliseconds. 
        var now = new Date().getTime(); 
        //Set alarm for 3 seconds time. 
        app.SetAlarm( "Set", 1234, OnAlarm, now + 3000 ); }
 
//Called when user selects a menu item.
function OnMenu( name )
{        		
	app.ShowPopup( "OnMenu( " + name + " )" );
}
 
//Called when the back key is pressed.
function OnBack() 
{              
	alert( "OnBack" );   
	app.Exit();
}
 
//Called when application is paused.
//(eg. When user switches to home screen)
function OnPause() 
{ 
	app.ShowPopup( "OnPause" );
}
 
//Called when application is resumed.
//(eg. When user returns from home screen)
function OnResume() 
{ 
	app.ShowPopup( "OnResume" );
}
 
//Called when configuration changes.
//(eg. When user rotates phone)
function OnConfig() 
{              
	app.ShowPopup( "OnConfig" );    
}
 
//Called when alarm is triggered. 
//(Even if your app is closed) 
function OnAlarm( id ) 
{ 
    app.ShowPopup( "Got Alarm: id = " + id ); 
} 
 
//Handle data sent from other apps.
function OnData( isStartUp )
{
   	//Display intent data.
	var intent = app.GetIntent();
	if( intent )
	{
            //Extract main data.
            var s = "action: " + intent.action + "\n";
            s += "type: " + intent.type + "\n";
            s += "data: " + intent.data + "\n\n";
 
            //Extract extras.
            s += "extras:\n";
            for( var key in intent.extras ) 
                s += key+": "+intent.extras[key] + "\n";
 
            app.Alert( s, "OnData" ); 
	}
}

OnConfig

The following code can be useful if you want to change the layout in the OnConfig event.

//Called when application is started.
function OnStart()
{
  //Create a layout with objects vertically centered.
  lay = app.CreateLayout( "linear", "VCenter,FillXY" );  
  var test = app.GetOrientation();
  var hv = "Vertical";
  if( test=="Landscape") hv= "Horizontal";
  lay.SetOrientation( hv );
 
  txt = app.CreateText( "Hello " );
  txt.SetTextSize( 64);
  lay.AddChild( txt );
 
  txt1 = app.CreateText( "Goodbye" );
  txt1.SetTextSize( 64 );
  lay.AddChild( txt1 );
  app.AddLayout( lay );
}
//Called when screen rotates
function OnConfig()
{
  var test = app.GetOrientation();
  var hv = "Vertical";
  if( test=="Landscape") hv= "Horizontal";
  lay.SetOrientation( hv );
}
built_in/app_events.1546134465.txt.gz · Last modified: 2018/12/30 09:47 (external edit)