Call function when app is closed

I need help, I do not know how to make a function call in the background when the application is closed, it only works if it is open or minimized.

    platform.ready().then(() => { 
      this.backgroundMode.setDefaults({ silent: true });
      this.backgroundMode.enable();
      backgroundMode.on('enable').subscribe(() => { 
        setInterval(() => {
          this.getBusqueda();
        }, 5000);
      }); 

When your app is closed, that means that the user does not want it eating their battery. Would you please respect that?

The function I want to run in the background, is simply a function that checks whether a notification should arrive and displays it.

same problem here, for push notification with onesignal

you can use this ;

if(this.platform.exitApp){
      this.storage.set('forceClose','this apps has been closed');
    // or something function
    }

Hi @rafikbojes
Do you write this script in the app.component.ts constructor ?
thanks

Hi, have you solved the issue? I’m struggling with a same issue. can you help me please