Platform.pause / platform.resume not working?


#1

I’m using the typical way to detect app pause / resume in a Cordova app. But this does not work with capacitor:

initializeApp() {
    this.platform.ready().then(() => {
      this.statusBar.styleDefault();
      this.splashScreen.hide();
      console.log('App is ready');

      this.platform.pause.subscribe(test => {
        console.log('App paused.');
      });
      this.platform.resume.subscribe(test => {
        console.log('App resumed.');
      });
    });
}

the console.logs are never printed…


#2

Good catch, doesn’t look like we’re emitting the pause and resume events in Capacitor. Making a note of that.

In the meantime you can use the App API to listen for app state changes (pause/resume):

import { Plugins, AppState } from '@capacitor/core';

const { App } = Plugins;
App.addListener('appStateChange', (state: AppState) => {
  // state.isActive contains the active state
  console.log('App state changed. Is active?', state.isActive);
});