i want to call a function when ionic 3 app destroy …
if anyone having idea about this please help me to find out the right solution
THANKS
i want to call a function when ionic 3 app destroy …
if anyone having idea about this please help me to find out the right solution
THANKS
@jaggu07 I don’t know a way to run a fuction when the app is destroyed (because there is no way I see to guarantee that such function will run, after all the app could be forcibly killed). What you can do is to use the pause
function (I’m assuming you are talking about a native app, not a PWA, I don’t know how it works for PWA):
import { Platform } from 'ionic-angular';
constructor(private platform: Platform) { }
public pause(): Observable<Event> {
this.platform.pause.subscribe(() => console.log('paused');
}
When the app goes to the background the function will run (the app is still running, but in background).
After you enter the app it is resumed (this.platform.resume.subscribe(() => console.log('resumed'));
), but if you open other apps while your app is in background, the OS may chose to kill your app (even if you don’t close it explicitly), so the pause
in this case works like a function that is called when the app is destroyed.
The only case in which it will have a different behaviour (than the destroy function that you asked) is if you send the app to the background and reopen it before the OS kills it.
I don’t know your use case though, but the pause
function may work fine.
This question seems related to yours:
Thanks for your reply @lucasbasquerotto