tsteward Well-Known Member Licensed User Longtime User Feb 18, 2017 #1 I'm trying to write a timer where the user will select X minutes. I have a display and also a service running in case the screen is off. But the service does not fire at exactly 60 seconds if the user selected 1 minute. What am I doing wrong please? Attachments timer.zip timer.zip 73.7 KB · Views: 385
I'm trying to write a timer where the user will select X minutes. I have a display and also a service running in case the screen is off. But the service does not fire at exactly 60 seconds if the user selected 1 minute. What am I doing wrong please?
Erel B4X founder Staff member Licensed User Longtime User Feb 19, 2017 #2 Is the timer accurate? A more accurate version of StartServiceAt: https://www.b4x.com/android/forum/t...estartatexact-not-accurate.65117/#post-412286 Upvote 0
Is the timer accurate? A more accurate version of StartServiceAt: https://www.b4x.com/android/forum/t...estartatexact-not-accurate.65117/#post-412286
tsteward Well-Known Member Licensed User Longtime User Feb 19, 2017 #3 Thank you Erel that fixed the problem Upvote 0
M Mahares Expert Licensed User Longtime User Feb 19, 2017 #4 Erel said: A more accurate version of StartServiceAt: Click to expand... tsteward said: Thank you Erel that fixed the problem Click to expand... I tested your example using each of these 3 nuances using a time of 1 minute and did not see any difference between the three. All seem to work properly. The first number you see after the timer starts is of course 58 seconds. Code: Copy StartServiceAt(alarm, targetTime, True) StartServiceAtExact(alarm, targetTime, True) SetExactAndAllowWhileIdle (targetTime, "alarm") What did you see that I could not see/ Upvote 0
Erel said: A more accurate version of StartServiceAt: Click to expand... tsteward said: Thank you Erel that fixed the problem Click to expand... I tested your example using each of these 3 nuances using a time of 1 minute and did not see any difference between the three. All seem to work properly. The first number you see after the timer starts is of course 58 seconds. Code: Copy StartServiceAt(alarm, targetTime, True) StartServiceAtExact(alarm, targetTime, True) SetExactAndAllowWhileIdle (targetTime, "alarm") What did you see that I could not see/
Erel B4X founder Staff member Licensed User Longtime User Feb 19, 2017 #5 The difference in "the more accurate version" is only relevant to Android 6+ and it is also possible that you will not see any difference. It prevents the OS from changing the scheduled time to preserve battery power. Upvote 0
The difference in "the more accurate version" is only relevant to Android 6+ and it is also possible that you will not see any difference. It prevents the OS from changing the scheduled time to preserve battery power.
tsteward Well-Known Member Licensed User Longtime User Feb 19, 2017 #6 Mahares said: I tested your example using each of these 3 nuances using a time of 1 minute and did not see any difference between the three. All seem to work properly. The first number you see after the timer starts is of course 58 seconds. Code: Copy StartServiceAt(alarm, targetTime, True) StartServiceAtExact(alarm, targetTime, True) SetExactAndAllowWhileIdle (targetTime, "alarm") What did you see that I could not see/ Click to expand... The timer on the screen ran just fine but the service that would sound the alarm was inconsistent. About 10% of the time it would fire on time but the other 90% of the time it was 10, 14, 38 etc seconds late. Using SetExactAndAllowWhileIdle (targetTime, "alarm") it now fires on time, every time on my LG G4 android 6.0 Upvote 0
Mahares said: I tested your example using each of these 3 nuances using a time of 1 minute and did not see any difference between the three. All seem to work properly. The first number you see after the timer starts is of course 58 seconds. Code: Copy StartServiceAt(alarm, targetTime, True) StartServiceAtExact(alarm, targetTime, True) SetExactAndAllowWhileIdle (targetTime, "alarm") What did you see that I could not see/ Click to expand... The timer on the screen ran just fine but the service that would sound the alarm was inconsistent. About 10% of the time it would fire on time but the other 90% of the time it was 10, 14, 38 etc seconds late. Using SetExactAndAllowWhileIdle (targetTime, "alarm") it now fires on time, every time on my LG G4 android 6.0