Android Question Timer to set alarm for X seconds

tsteward

Well-Known Member
Licensed User
Longtime User
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
    73.7 KB · Views: 219

Mahares

Expert
Licensed User
Longtime User
A more accurate version of StartServiceAt:

Thank you Erel that fixed the problem
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.
B4X:
StartServiceAt(alarm, targetTime, True)
    StartServiceAtExact(alarm, targetTime, True)
    SetExactAndAllowWhileIdle (targetTime, "alarm")
What did you see that I could not see/
 
Upvote 0

tsteward

Well-Known Member
Licensed User
Longtime User
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
Cookies are required to use this site. You must accept them to continue using the site. Learn more…