1

I've been using Platform's pause and resume event like in the code below but I want to handle exit event when a user closes the app instead of taking app in the background.

this.platform.ready().then(() => {

      if (this.platform.is('cordova')){
        this.platform.pause.subscribe(() => {
          this.stopTimer();
        });
       }
});

Is there a way any help will be appriciated.

Black Mamba
  • 13,632
  • 6
  • 82
  • 105
  • 2
    I think there is no event that will be triggered, when closing the app. In most cases the app will be closed in pause mode anyways (I don't know if it is even possible to close the app in another way). No code will execute when you close the app via explorer – Stephan Strate Jun 30 '18 at 07:31
  • 2
    @StephanStrate is right, there is no event to capture the app exit, see the [overview of cordova events here](https://cordova.apache.org/docs/en/latest/cordova/events/events.html). I've also written a little more about the cordova lifecycle events [here](https://stackoverflow.com/a/50526589/5730444). Maybe it is helpful... – Phonolog Jun 30 '18 at 07:34
  • https://stackoverflow.com/questions/19568315/how-to-handle-code-when-app-is-killed-by-swiping-in-android/26882533#26882533 I see it's possible in android might be someone has a plugin for `ios` and `android` @StephanStrate @Phonolog – Black Mamba Jun 30 '18 at 09:14
  • @BlackMamba I'm not aware of such a plugin, but of course you can try to implement your own... – Phonolog Jul 01 '18 at 06:18

1 Answers1

0

For browser, you can try something like this, accessing window events directly:

window.addEventListener('beforeunload', () => {
  this.OptionsSave();
});
Luca C.
  • 11,714
  • 1
  • 86
  • 77