katzer / cordova-plugin-background-mode

Keep app running in background
Apache License 2.0
1.38k stars 1.02k forks source link

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

Open JessicaMouta opened 4 years ago

JessicaMouta commented 4 years ago

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!!

pimol commented 4 years ago

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

JessicaMouta commented 4 years ago

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?

phpfile commented 4 years ago

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

ersaurabh101 commented 4 years ago

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 ?

igorcap commented 4 years ago

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

cordova.plugins.backgroundMode.on('activate', function() {
   cordova.plugins.backgroundMode.disableWebViewOptimizations(); 
});
renznamoc21 commented 4 years ago

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 ?

ragcsalo commented 4 years ago

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.)

sirthun commented 4 years ago

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