Problem with Timer App

I want a Timer App which could work even if I close My Phone Screen or If phone Screen gets off to save Power when idle. My timer App should continuously run its clock like Minutes, Seconds . I had designed an App with Clocks Using LABELS to Decrement Minutes, seconds as i want downTimer But when my phone screen is off due to idle and i turn it on to see where timer reached, it shows the the time when screen had slept and starts again counting and when screen again sleeps , it again stops counting and starts again upon awakening of the phone screen!! please can anyone help me with this issue!
NOTE : I did not used any global Timer or things like these i only used label texts for timer to count down from them so i used label text for reference to timer.

Hi younus

This requirement would normally require the use of Android Background Services, but App Inventor does not support them.

A work-around would be to use an extension that keeps the App running all the time, but of course that is expensive in terms of battery power (unless the phone has an external supply of power).

There is also a new extension that effectively mimics a background service. I have never put it to the test but it does actually sound as though it can meet your requirement.

I want the timer to run as long as App is not exit other wise it should be stopped when the App is not in use like when i click some exit button in my App it should get disabled again.

Yes indeed - the extension should deliver on that. The best way to know is to try it.

Another method that might work is to have a seperate Clock Timer constantly move or change something on screen, so the Phone knows the App is active. For example, displaying a tiny image and replacing it with another tiny image every 5 seconds or so, or perhaps re-sizing a label width that is used as a horizontal spacer.

if i failed to do the later then do suggest me how to import your free extension to App inventor then!
thanyou and bye for now....

Check this APK:

So try it out and report.

You could always approach this from a different angle, and work out when you are now from when you were then....use Taifun's Tools ActivityStateChanged event to grab the time and counter position when the app is paused, and to add the "gap" back to the counter on resume....

timerSleep.aia (24.9 KB)

2 Likes

Here's the extension-free solution, just comparing present time to a TinyDB saved millisecond ...
After Restart

Counting Start timer_abg.aia (3.2 KB)

2 Likes

Oops, I let my sample run longer, and I learned that my math was wrong in breaking up the Duration to hh:mm:ss.
I was thinking in decimal fractions, getting seconds > 60.

To get proper conversion, get a countdown timer from the Gallery, like
ai2.appinventor.mit.edu/?galleryId=6104963528523776

1 Like

I am working with this issue and i got resolution I had set my clock always fires to diable mode thats why the issue!

A post was merged into an existing topic: Problem with finding Block

my problem is solved my app is simple and need not extension as i had set my timer always fires to disable mode!

No, unfortunately that won't solve the problem, not even if TimerAlwaysFire is enabled.
On many devices, the Timer is stopped in idle mode (Doze) / background. So I recommend the approach from @ABG as the simplest solution (if you don't need to pause the Timer).

I finally got around to fixing my time math, and consolidated it all into a single value procedure (hh_mm_ss). Here is the new code:
After Restart Capture Counting

Start timer_abg.aia (5.4 KB)

(I got the idea to consolidate the time math into a single value procedure, after replacing an old ceiling fan with a new fan boasting of a greatly reduced parts count to ease installation.)

4 Likes

Hello Abraham,

this is really a very simple and also ingenious idea (approach) to solving the general problem with the inaccuracy of the Clock component and the problem in idle mode (sleep mode, timeout / Doze).
Great as always, thank you Abraham! :+1:

Greetings from Germany,
Anke

Btw, I had the same idea when creating my CountDownUp extension:

Thanks for the peep into Java, I'll save it for if and when I need to dive into extensions.

BTW, I suspect my hh_mm_ss procedure could be replaced with a Clock FormatTime call with the right pattern. I did not have time to shorten it.

@ABG So what is your solution if the timer (count up) is paused (even several times)?

That would probably require an extra saved variable, like accumulated runtime, like the Memory button on a calculator. That looks like a different problem statement to me.

Yes but how? Maybe like this: