Page 1 of 1

Timer stops

Posted: Thu Mar 27, 2014 12:08 pm
by ishani modi

Hi,

I have used timer in app and it stops as soon as the iPhone screen gets locked.
Please give me the solution for this
codevar sec = 0;
var min = 0;
var hour = 0;
function stopwatch() {
sec++;
if (sec == 60) {
sec = 0;
min = min + 1; }
else {
min = min; }
if (min == 60) {
min = 0;
hour += 1; }

if (sec<=9) { sec = "0" + sec; }

Code: Select all

&#47;&#47;document&#46;clock&#46;labelTimer&#46;value = ((hour<=9) ? "0"+hour : hour) + " : " + ((min<=9) ? "0" + min : min) + " : " + sec; 

var timevalue =((hour<=9) ? "0"+hour : hour) + " : " + ((min<=9) ? "0" + min : min) + " : " + sec;
$("#labelTimerValue")[0]&#46;innerHTML = timevalue;
window&#46;setTimeout("stopwatch();", 1000);
}/code
Thanks
Ishani.


Timer stops

Posted: Thu Mar 27, 2014 1:05 pm
by Maryna Brodina

Hello!

Timer stops because app goes into background mode. This is done battery economy. Background apps stop working, but there are PhoneGap plugins which can prevent that.
You would need to search for plugins online.


Timer stops

Posted: Thu Mar 27, 2014 1:55 pm
by ishani modi

Hi,
Thanks for explaining it.. Its good knowledge.
but I dont want to add any plugin,It will be great if you give solution other than this.
Please help


Timer stops

Posted: Thu Mar 27, 2014 2:12 pm
by Maryna Brodina

Unfortunately there is no other way.


Timer stops

Posted: Thu Apr 03, 2014 5:50 am
by ishani modi

Hi Maryna,
It is solved, I have modified the code


Timer stops

Posted: Thu Apr 03, 2014 8:06 am
by Kateryna Grynko

Hi Ishani,

Thank you for the update!


Timer stops

Posted: Mon May 05, 2014 3:30 pm
by Christopher Lowman

Ishani,

How did you figure this out and where did you paste that code in the original post? I am trying to get a stopwatch in my app as well.


Timer stops

Posted: Mon May 26, 2014 10:41 am
by ishani modi

Hi Chrishtopher I have placed this code in .js file under a function and called that function when page show events take place.


Timer stops

Posted: Tue Jun 03, 2014 3:35 pm
by Christopher Lowman

What code did you use?