var svc; //Called when application is started. function OnStart() { //Create a layout. var lay = app.CreateLayout( "linear", "VCenter,FillXY" ); //Create a 'Stop Service' button. var btn = app.CreateButton( "Stop Service", 0.6, -1 ); lay.AddChild( btn ); btn.SetOnTouch( btn_OnTouchStop ); //Add layout to app. app.AddLayout( lay ); //Start/connect to our service. svc = app.CreateService( "this","this", OnServiceReady ); //uncomment next line to cause your service to start at boot. //app.SetAutoBoot( "Service" ); } //Called after our service has started. function OnServiceReady() { console.log( "Service Ready" ); var running=false; var me=app.GetPackageName()+":droidscript_service"; var lst = app.GetRunningServices(); for (var key in lst) { if(lst[key].name === me) { console.log(me + " running"); break; } } } function btn_OnTouchStop() { //Tell service we are quitting. svc.SendMessage( "quit" ); //give the service time to clean up setTimeout(delayedStop,1000); } function delayedStop() { //Stop the service. svc.Stop(); // exit main app app.Exit(); } function OnData( isStartUp ) { var id=app.GetNotifyId(); if(id === "servFilx" ) { app.Alert("Notification touched") ; } }