Louis Adekoya
Posts: 0
Joined: Sun Nov 17, 2013 10:51 pm

Does JS Timer Continue in Background?

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.

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Does JS Timer Continue in Background?

Hello Louis,

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

Louis Adekoya
Posts: 0
Joined: Sun Nov 17, 2013 10:51 pm

Does JS Timer Continue in Background?

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.

Illya Stepanov
Posts: 0
Joined: Mon Mar 18, 2013 8:48 am

Does JS Timer Continue in Background?

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

Louis Adekoya
Posts: 0
Joined: Sun Nov 17, 2013 10:51 pm

Does JS Timer Continue in Background?

Thank you Illya.

Return to “Issues”