DroidScript wiki

(was AndroidScript) unofficial documentation by the community

User Tools

Site Tools


sample_code:app_toback

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

sample_code:app_toback [2014/12/21 15:53] (current)
octazid created
Line 1: Line 1:
 +======Send your App to the Background ======
 +Code from the DroidScript-Beta forum posted by Dave Smart
 +<code JavaScript appToBack.js>​
 +//Called when application is started.
 +function OnStart()
 +{
 +    //Create a layout with objects vertically centered.
 +    lay = app.CreateLayout( "​linear",​ "​VCenter,​FillXY"​ );    ​
 +    ​
 +    //Create a button.
 +    btn = app.CreateButton( "Send To Back", 0.6 );
 +    btn.SetOnTouch( btn_OnTouch );
 +    lay.AddChild( btn );
 +        ​
 +    //Add layout to app.    ​
 +    app.AddLayout( lay );
 +    ​
 +    //Create media player.
 +    player = app.CreateMediaPlayer();​
 +    ​
 +    //Load a file (can be ogg or mp3).
 +    player.SetFile( "/​Sys/​Snd/​Poing.ogg"​ );
 +    player.SetLooping( true );
 +}
  
 +//Called when user touches our button.
 +function btn_OnTouch()
 +{
 +    //Set alarm for 5 seconds time.
 +    var now = new Date().getTime();​
 +    app.SetAlarm( "​Set",​ 1234, OnAlarm, now + 5000 );
 +    ​
 +    //Set sound playing repeatedly.
 +    //​setInterval( PlaySound, 1000 );
 +    player.Play();​
 +    ​
 +    //Send app to back.
 +    app.ToBack(); ​   ​
 +}
 +
 +//Called when alarm is triggered.
 +//(Even if your app is closed)
 +function OnAlarm()
 +{
 +    app.ShowPopup( "​Hello!"​ );
 +}
 +
 +//Play the sound.
 +function PlaySound()
 +{
 +    player.SeekTo( 0 );
 +    player.Play();​
 +}
 +</​code>​
sample_code/app_toback.txt ยท Last modified: 2014/12/21 15:53 by octazid