Service doesn't run on ChromeBook when app is closed.

53 views
Skip to first unread message

davefinney

unread,
Jul 3, 2023, 8:56:14 AM7/3/23
to DroidScript
The service below runs on a phone both with the app open and when the app is closed.

The service does run on ChromeBook when the app is open (full-screen, small or minimised), but stops when the app is closed.

Services clearly do run on ChromeBooks with apps closed, so does the service require something extra to work on ChromeBooks?

********
ABC counts seconds from app start.
Stat counts minutes from service start.

******** App *********

function OnStart()
{
    svc = app.CreateService( "this", "this" );
    svc.SetOnMessage( Reply );
    svc.SetInBackground();
    app.SetAutoBoot( "Service" );
   
    Btn = app.CreateText( "Hello", 0.5, 0.5, "Multiline,VCenter" );
    Btn.SetTextSize( 24, "dip" );
    Btn.SetBackColor( "#ff282828" );
    Btn.SetOnTouchDown( BtnTch );
   
    lay = app.CreateLayout( "linear", "VCenter" );
    lay.AddChild( Btn );
    app.AddLayout( lay );
}

function BtnTch()
{
    svc.SendMessage( "A" );
}

function Reply( x )
{
    Btn.SetText( x );
}

******** Service *********

function OnStart()
{
    var a = app.LoadNumber("Serv", 0, "B");
    Stat = a > 0 ? a : 0;
   
    app.SetAlarm( "Repeat", 1, StatPlus, Date.now() + 60000, 60000 );
   
    ABC = 0;
    Timer = setInterval( update, 1000 );
}

function StatPlus()
{
    Stat ++;
    app.SaveNumber( "Serv", Stat, "B" );
}

function update()
{
    ABC ++;
    app.SendMessage( Stat +"\n"+ ABC );
}

function OnMessage( Str )
{
    ABC *= -1;
}
Reply all
Reply to author
Forward
0 new messages