App is in forground or background

Hi, How to know whether app is running in foreground or background(like resume, pause etc states).
So please help me with any example . Thanks in advance.

Platform contains pause and resume event emitters.

THanks for reply, any examples please.

I’m not sure what you mean by wanting to know if the app is running in the foreground.

But for a background check, I’m guessing a simple solution would be to create a timer that changes something in the HTML? Like create a <p *ngIf="timeUp">Worked in background</p>

Also create HTML when you pause and resume.

Try using this plugin:

import { BackgroundMode } from '@ionic-native/background-mode';

constructor(private backgroundMode: BackgroundMode) { 
   this.backgroundMode.on('activate').subscribe(() => console.log('Running in Background'))
   this.backgroundMode.on('deactivate').subscribe(() => console.log('Back to Foreground'))
   this.backgroundMode.enable()
}

Don´t forget to add the module reference to AppModule.