ishani modi
Posts: 0
Joined: Wed Oct 23, 2013 4:49 am

Timer stops

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.

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Timer stops

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.

ishani modi
Posts: 0
Joined: Wed Oct 23, 2013 4:49 am

Timer stops

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

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Timer stops

Unfortunately there is no other way.

ishani modi
Posts: 0
Joined: Wed Oct 23, 2013 4:49 am

Timer stops

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

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Timer stops

Hi Ishani,

Thank you for the update!

Christopher Lowman
Posts: 0
Joined: Tue Apr 08, 2014 10:42 am

Timer stops

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.

ishani modi
Posts: 0
Joined: Wed Oct 23, 2013 4:49 am

Timer stops

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

Christopher Lowman
Posts: 0
Joined: Tue Apr 08, 2014 10:42 am

Timer stops

What code did you use?

Return to “Issues”