title: Event to handle app is closed (Ionic)
body: <p>I'm running a process in background and I need to kill it before the app is closed from recent apps (swiping to right whit the square button).</p>
  
  <p>The app use a plugin to get the current location <a href="https://github.com/mauron85/cordova-plugin-background-geolocation" rel="nofollow">https://github.com/mauron85/cordova-plugin-background-geolocation</a> and another to make the task in background. The background plugin calls to the location plugin, and if you swipe the app during the location is being stored the notification keeps in the drawer.</p>
  
  <pre><code>if(window.cordova &amp;&amp; window.cordova.plugins.Keyboard) {
  
        cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
  
        cordova.plugins.backgroundMode.enable();
  
        cordova.plugins.backgroundMode.onactivate = function () {
  
          if(promise != []){
            $interval.cancel(promise);
          }
          promise = $interval(geolocation_function, 25000);
        };
  
        cordova.plugins.backgroundMode.ondeactivate = function(){
          if(promise != []){
            $interval.cancel(promise);
          }
  
          promise = $interval(geolocation_function, 25000);
        }
      }
  </code></pre>
  
  <p>The geolocation function call to the background plugin. I'm using this <a href="https://github.com/katzer/cordova-plugin-background-mode" rel="nofollow">https://github.com/katzer/cordova-plugin-background-mode</a> and I don't know how to control this.</p>
  
  <p>Is there any function I can use for that? Thanks.</p>