How to check when app is in the background


#1

I checked all over for plugins or tutorials and could not find {N} API that offers the ability to check if app is in the background or foreground. I’m guessing one will have to call native APIs to do that? Am I correct or is there some documentation someone can point me to?


#2

I hope this can help you: https://docs.nativescript.org/core-concepts/application-lifecycle#use-application-events

var application = require("application");

// App went to background...
application.on(application.suspendEvent, function (args) {
    if (args.android) {
        // For Android applications, args.android is an android activity class.
        console.log("Activity: " + args.android);
    } else if (args.ios) {
        // For iOS applications, args.ios is UIApplication.
        console.log("UIApplication: " + args.ios);
    }
});

// App was reopened...
application.on(application.resumeEvent, function (args) {
    if (args.android) {
        // For Android applications, args.android is an android activity class.
        console.log("Activity: " + args.android);
    } else if (args.ios) {
        // For iOS applications, args.ios is UIApplication.
        console.log("UIApplication: " + args.ios);
    }
});

#3

This is awesome, thank you for this!!