Executing code if App is in background

Hi, I am using a 3rd party native plugin which has 1 method that keeps the application running even if you kill it (you must force the close in the settings).

This plugin has a method to stop doing that but I don’t know where I should call that method when the application is “killed”. It works on ionViewWillLeave but the problem is if the user closes the App while in the page the 1st method is called.

Thanks.

I don’t know what’s happening exactly, but one way of bypassing the issue (btw you should fix the issue not bypass it) is by making a global variable, call it something like firstMethodIsAllowedToRun and make it true. When ionViewWillLeave is executed put it on false and then write the following if statement at the top of the first method:

if (!this.firstMethodIsAllowedToRun) {
    return;
}

That method is allowed.

The scenario is:

  • I have a page that runs 1 method continuosly
  • If I kill the application the method continues running in background, it seems. There is a notification which says “App is running in background” or something similar. And the only way to stop it is to go to the App’s configuration and force close it.

What I want is that if I kill the App, it stops completly whatever it’s running and not to stay in that mode.

Really depends on what the background process is doing.
The method I gave you can still work unless you’re maybe working with async calls or whatever.

I solved this pausing the method that makes the App keep executing with the .pause event and if the user comes back to the App I just run the needed methods with the .resume event from Platform