Back

GetRunningApps

Hello World

Returns a list of objects containing info about all currently running apps in the fore- or background.

app.GetRunningApps() → list: of objects: [{ user, pid, name, foreground }]

See Also: GetRunningServices, GetInstalledApps

Example - Show Running Apps

function OnStart()
{
    app.ShowProgress();

    var lay = app.CreateLayout( "linear", "fillxy,vcenter" );

    lst = app.CreateList( "", .9, .9 );
    lst.SetTextSize1( 15 );
    lay.AddChild( lst );

    var list = app.GetRunningApps();

    for( var i in list )
    {
        var a = list[i];
        var body =
            "user: " + a.user +
            "\npid: " + a.pid +
            "\nforeground: " + a.foreground;
        lst.AddItem( a.name, body );
    }


    app.AddLayout( lay );

    app.HideProgress();
}
    Copy     Copy All       Run      

Example - Is In Foreground

function OnStart()
{
    app.Animate(CheckForeground, 0.2);
}

function CheckForeground()
{
    var apps = app.GetRunningApps();
    var name = app.GetPackageName();
    if(!app.IsAPK()) name += ":NewActivityProcess";

    for(var i in apps)
    {
        if(apps[i].name == name)
            app.ShowPopup("In Foreground: " + apps[i].foreground);
    }
}
Copy All       Run      
boolean
string
number
number: integer