cordova-plugin-background-mode icon indicating copy to clipboard operation
cordova-plugin-background-mode copied to clipboard

The plugin does not work in the background for more than 30 minutes

Open JessicaMouta opened this issue 5 years ago • 8 comments

The plugin does not work in the background for more than 30 minutes. My code is this: init() { this.platform.ready().then(() => { this.activeBackgroundMode(); this.powerManagement.dim(); this.powerManagement.setReleaseOnPause(false); }); } activeBackgroundMode(){ this.backgroundMode.enable(); this.backgroundMode.on('activate').subscribe(() => { this.backgroundMode.disableWebViewOptimizations(); this.backgroundMode.disableBatteryOptimizations();

    this.activePolling();

  });

already updated the plun but contained not working.

Can someone help me!!

JessicaMouta avatar Feb 06 '20 21:02 JessicaMouta

In attach a simple test (.ts and .html files) I used to test the plugin with Android 8 and 9. Simply, it run a counter so you can see if it works in background or not.

I hope it help. home.page.zip

pimol avatar Feb 06 '20 21:02 pimol

The problem is it seems that the plugin works only for a while, in my tests it lasted up to an hour, but then it closes .. my app needs to do a pooling to keep a company online and receive orders.

a function: this.bkgng.moveToBackground(); makes any difference?

JessicaMouta avatar Feb 07 '20 13:02 JessicaMouta

Make sure you don't disable the running notification. Don't use this: cordova.plugins.backgroundMode.setDefaults({ silent: true });

phpfile avatar Feb 08 '20 09:02 phpfile

Hey,

Did you find something which keeps the app running ?

I have a similar requirement - Delivery app - suppliers wants continuous bell even if app is closed till action

Please guide me as you have already tried all this How did you manage this ?

ersaurabh101 avatar May 04 '20 04:05 ersaurabh101

I was having the same problem. I manage to fix it by doing:

cordova.plugins.backgroundMode.on('activate', function() {
   cordova.plugins.backgroundMode.disableWebViewOptimizations(); 
});

igorcap avatar May 07 '20 13:05 igorcap

I was having the same problem. I manage to fix it by doing:

cordova.plugins.backgroundMode.on('activate', function() {
   cordova.plugins.backgroundMode.disableWebViewOptimizations(); 
});

where do you put this event ?

renznamoc21 avatar May 12 '20 06:05 renznamoc21

I have put it like this:

          cordova.plugins.backgroundMode.enable();
          
          setTimeout(function() {
            cordova.plugins.backgroundMode.on('activate', function() {
              console.log('backgroundMode ACTIVE: '+cordova.plugins.backgroundMode.isActive());
              cordova.plugins.backgroundMode.disableWebViewOptimizations();
              setTimeout(function() {
                cordova.plugins.backgroundMode.configure({
                  title: "MyApp",
                  text: "The app is running in the background...",
                  resume: true,
                  hidden: true,
                  bigText: false
                });
              },2000);
            });
            cordova.plugins.backgroundMode.on('deactivate', function() {
              console.log('backgroundMode INACTIVE: '+cordova.plugins.backgroundMode.isActive());
            });
          },1000);

(However, changing the notification parameters doess not work.)

ragcsalo avatar May 12 '20 16:05 ragcsalo

I was having the same problem. I manage to fix it by doing:

cordova.plugins.backgroundMode.on('activate', function() {
   cordova.plugins.backgroundMode.disableWebViewOptimizations(); 
});

I'm try this event ,But the app will be called every time when switching to another app Makes it impossible to use other apps easily

sirthun avatar Jun 10 '20 09:06 sirthun