How to Know When My App Has Been Killed

How to know when my app has been killed?

there's no way to determine when a process is killed.
From How to detect if android app is force stopped or uninstalled?

When a user or the system force stops your application, the entire
process is simply killed. There is no callback made to inform you that
this has happened.

When the user uninstalls the app, at first the process is killed, then
your apk file and data directory are deleted, along with the records
in Package Manager that tell other apps which intent filters you've
registered for.

android, how to tell whether the app is in killed state by packagename

In a comment you wrote:

I want to determine: should the app go through a fresh re-launch (app
is killed) or just bring the app to front?

If you use a "launch Intent", this will handle all of this for you. If the app is already running, it will just bring the app to the foreground in whatever state it was in. If the app is not running, it will launch the app fresh.

To get a "launch Intent", you can use PackageManager.getLaunchIntentForPackage()

How to detect an application in the kill app on react native?

Try This :

componentDidMount() {
AppState.addEventListener('change',
this.handleAppStateChange);
}

componentWillUnmount() {
AppState.removeEventListener('change', this.handleAppStateChange);
}

handleAppStateChange = (nextAppState) => {
if (nextAppState === 'inactive') {
console.log('the app is closed');
}
}


Related Topics



Leave a reply



Submit