Reputation: 3234
I want to run some code when application is cleared from background . I know when when application get clear using swipe up from application list the cordova pause
event get called like below code i have written the code inside pause
method but its not getting called.
Here is my code..
platform.ready().then(() => {
if (platform.is('cordova')) {
//Subscribe on pause
this.platform.pause.subscribe(async() => {
await this.save();//this method is not executing i am storing the values in local storage here.
});
this.platform.resume.subscribe(() => {
}
});
}
});
Any idea what is the best way to store data when application force to close or clear from the application list
Upvotes: 0
Views: 911
Reputation: 4046
There is no way to handle a forced close in your app. If the user wants to kill it, he will be able to and you won't notice.
The only workaround I have found is to use the background mode with this plugin (look for the one that matches your Ionic version).
That way your are going to be able to keep doing tasks in the background, and you can store the data you need. In addition to this, you can handle the back button event also.
Upvotes: 1