Back

SetInBackground

JS Py
Hello World

Set the current service to run in the background.

app.SetInBackground()

See Also: StartService, SetInForeground.

Example - 2

var serviceJS = `
function OnStart()
{
    var i = 0;
    setInterval( function() { app.ShowPopup(i++); }, 2000 );
}

function OnMessage( msg)
{
    if( msg == "fg" ) app.SetInForeground( "My Service", "Service is running", "/Sys/Img/Hello.png", "/Sys/Img/Icon.png", "low");
    else if( msg == "bg" ) app.SetInBackground();

}
`
;

function OnStart()
{
    app.WriteFile( "Service.js", serviceJS );

    lay = app.CreateLayout( "linear", "VCenter,FillXY" );

    tgl = app.CreateToggle( "Foreground", 0.3, 0.1 );
    tgl.SetOnTouch( tgl_OnTouch );
    lay.AddChild( tgl );

    app.AddLayout( lay );

    svc = app.CreateService( "this", "this", OnSvcStart );
}

function tgl_OnTouch( fg )
{
    if( fg ) svc.SendMessage( "fg" );
    else svc.SendMessage( "bg" );
}
from native import app

serviceJS = """
def OnStart():
    i = 0
    def show_popup():
        nonlocal i
        app.ShowPopup(i)
        i += 1
    app.SetInterval(show_popup, 2000)

def OnMessage(msg):
    if msg == "fg":
        app.SetInForeground("My Service", "Service is running", "/Sys/Img/Hello.png", "/Sys/Img/Icon.png", "low")
    elif msg == "bg":
        app.SetInBackground()
"""


def OnStart():
    app.WriteFile("Service.js", serviceJS)

    lay = app.CreateLayout("linear", "VCenter,FillXY")

    tgl = app.CreateToggle("Foreground", 0.3, 0.1)

    def tgl_OnTouch(fg):
        if fg:
            svc.SendMessage("fg")
        else:
            svc.SendMessage("bg")

    tgl.SetOnTouch(tgl_OnTouch)
    lay.AddChild(tgl)

    app.AddLayout(lay)

    svc = app.CreateService("this", "this", OnSvcStart)
    Copy     Copy All       Run