Life cycle events (pause, resume) not triggered


#1

I simply cannot figure out how to retrieve lifecycle event notifications (tested on 2.1.8 and 2.1.13) - I have tried the following (in app.component.ts created with ionic start this-test --v2:

export class MyApp {
  constructor(private platform: Platform) {
    this.platform.pause.subscribe(e => {
      alert('pause - subscribe');
    });
    document.addEventListener('pause', () => {
      alert('pause - document');
    });
    ...

I see nothing when pressing the home button (same if adding handlers for resume, same if adding handlers in the constructor of a page class, same if not showing an alert or logging but e.g. just incrementing a counter). Same problem on device and emulator.

Could this be a bug in Ionic? It is quite central functionality and I have not seen other reports, so I doubt it - but I simply cannot see what I am doing wrong.

$ ionic info

Your system information:

Cordova CLI: 6.4.0 
Ionic Framework Version: 2.0.0-rc.3
Ionic CLI Version: 2.1.13
Ionic App Lib Version: 2.1.7
Ionic App Scripts Version: 0.0.45
ios-deploy version: 1.9.0 
ios-sim version: 5.0.8 
OS: macOS Sierra
Node Version: v6.2.1
Xcode version: Xcode 8.1 Build version 8B62

Thanks for any input!

Ulrik


#2

Never mind … if I just do a simple operation (like incrementing a counter), it works like a charm now (through document.addEventListener('pause', () => {...})). I am not exactly sure what I did differently when I wrote the initial post - perhaps I combined alerts with incrementing the counter? Alerts seem to cause trouble in the event handlers.


#3

Hi @gammelby - this seems to be a useful thread. When you say incrementing a counter - would this be a variable within the this.platform.pause.subscribe, or outside of it?