Search code examples
angularionic-frameworkbackground-mode

Run function when background mode is active using ionic 4


I am using the ionic Background Mode plugin. First, I installed in the project, imported in the app.module.ts file and put this code in app.component.ts file this.backgroundMode.enable();. I want to check if background mode is active in the background run function. I want to run my function when the background mode is active.

let inBackground = true;

this.backgroundMode.isActive();

this.myfunction();

Does anyone know how to do this??


Solution

  • Better to do it as in example below:

    this.backgroundMode.on('activate').subscribe(s => {
            console.log('backgroundMode activate');
     });
     this.backgroundMode.enable();
    

    More information about it you can take from this Cordova Background Plugin