Page 1 of 1

Does JS Timer Continue in Background?

Posted: Sun Sep 06, 2015 7:57 pm
by Louis Adekoya

I have the following code in a generic JS script:

code
var timeOut = 5 * 60 * 1000;
var onTimeout = function(){
console.log("session expired");
localStorage.setItem('CheckSessionToken', "true");
};
var onAjax = function(){
console.log("ajax clear current timer and run new");
window.clearTimeout(self.noActivityTimer);
self.noActivityTimer = window.setTimeout(onTimeout, timeOut);
};
jQuery(document).ajaxStart(onAjax)
/code

When my app (Android apk) goes into the background, the CheckSessionToken storage variable is not always set to true. Sometimes it is but most times it isn't. So my question is does the javascript timer continue to run when an android app goes to 'sleep'?

Fyi, I do have a pageshow trigger in an OnResume JS script as well, and the code in the page show checks for the value of CheckSessionToken, but I don't know if this is relevant.


Does JS Timer Continue in Background?

Posted: Mon Sep 07, 2015 6:07 pm
by Serhii Kulibaba

Hello Louis,

Please look this topic: http://community.phonegap.com/nitobi/...


Does JS Timer Continue in Background?

Posted: Mon Sep 07, 2015 6:49 pm
by Louis Adekoya

Thanks Sergiy. The post suggests that (for Android) one should put

< preference name="KeepRunning" value="true" /
< preference name="exit-on-suspend" value="false" /
(without spaces after "" )

in config.xml

Where can I find this in Appery.io - I can't find a config.xml file in the source. Also, the post says:

"Android will not stop javascript background execution.
Then, Android can close your app while in background for any reason."

I wonder if the second sentence is a typo. I don't want my app to be closed unnecessarily.


Does JS Timer Continue in Background?

Posted: Tue Sep 08, 2015 9:12 am
by Illya Stepanov

Hi - Please check screen shot: http://prntscr.com/8dxg3o


Does JS Timer Continue in Background?

Posted: Tue Sep 08, 2015 9:12 pm
by Louis Adekoya

Thank you Illya.