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

javascript code(an $interval function) doesn't run in background mode on android8

Open ITKing80 opened this issue 6 years ago • 12 comments

On android 6, it works like a charm. But on android 8, the $interval function doesn't run. Does anyone get the same issue?

ITKing80 avatar Jul 11 '18 10:07 ITKing80

@ITKing80 Hi I have the same issue. the background mode only runs for about 5 mins, then the app is not running anymore, anyone has a solution?

gavin1818 avatar Aug 07 '18 04:08 gavin1818

Same issue in Samsung Galaxy S8 Android Oreo 8.0

magancete avatar Sep 09 '18 11:09 magancete

It works perfectly for me, but when the application is in the foreground. However, when the application goes to the second plane, after 10 minutes it stops.

santiagovasquez avatar Sep 12 '18 18:09 santiagovasquez

I have solved it using setTimeout recursively to create something similar to setInterval

magancete avatar Sep 12 '18 18:09 magancete

I have solved it using setTimeout recursively to create something similar to setInterval

It works. You saved my life!

ITKing80 avatar Sep 14 '18 09:09 ITKing80

@magancete how are you, can you please share me , you function with seTimeout. since in the device after 10m to freeze the interval :(

santiagovasquez avatar Sep 14 '18 15:09 santiagovasquez

@magancete how are you, can you please share me , you function with seTimeout. since in the device after 10m to freeze the interval :(

vat time = //time you want in miliseconds;
var timer = setTimeout(function request() {    
     if(condition){
          //do something
     } else {
          time = newTime;
          timer = setTimeout(request, time);
     }     
}, time);

If you want to clear timer use clearTimeout(timer);

magancete avatar Sep 14 '18 21:09 magancete

@magancete Thanks so much.

santiagovasquez avatar Sep 15 '18 01:09 santiagovasquez

@santiagovasquez @magancete Does this fix still work? I am facing a similar challenge with using setInterval and I used the solution mentioned using timeout but still it stops working after 5 mins at the background.

meghajayakumar avatar Jul 10 '20 13:07 meghajayakumar

i have the same problem of @meghajayakumar. After 5 min these functions stop working:

  • recursive setTimeout()
  • setInterval()
  • rxjs interval()

FrancescoPaiola avatar Jun 24 '21 14:06 FrancescoPaiola

Solved using this:

this.backgroundMode.on('activate').subscribe(() => {
	this.backgroundMode.disableWebViewOptimizations();
	this.backgroundMode.disableBatteryOptimizations();
});

FrancescoPaiola avatar Jun 24 '21 14:06 FrancescoPaiola

@FrancescoPaiola Where did you put these lines?

riccardocostantini avatar Nov 13 '23 08:11 riccardocostantini