DroidScript wiki

(was AndroidScript) unofficial documentation by the community

User Tools

Site Tools


Sidebar

News

Version1.42 is out since December 2nd 2016


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

sample_code:app_toback

Send your App to the Background

Code from the DroidScript-Beta forum posted by Dave Smart

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();
}
sample_code/app_toback.txt · Last modified: 2014/12/21 15:53 by octazid