Android Question State Machine / Timers

ih8krrotz

New Member
Licensed User
Longtime User
I’m currently porting a pocket PC application to Android. This application uses 3 timers: 1s preset, 100ms preset and 50ms preset. I was not the one that wrote the pocket PC app, but from what I know it runs reasonably well.

I'm used to design embedded devices with hardware timers that are accurate and timer-interrupts that are trigger as expected (no delays), but unfortunately I found out that timer(Android) is not accurate and after doing some research here in the forum, I could confirm it.

Using while loop or similar is not a good choice as in this case the 100ms timer runs a state machine and the 50ms timer polls information from a device, which means I cannot hold the entire app to count time.

I would like to know if anyone has come through the same kind of scenario or if someone can suggest what would be the best solution for this type of application.

Thanks in advance.
 

stevel05

Expert
Licensed User
Longtime User
It may not be the best solution, but for a time critical app, I run a process in a separate thread and in a do loop, check the delay-time against datetime.now.

This won't hang the process. If you want to interact with the UI you need to use the RunOnGuiThread method from the Thread Object.

It's performance seems pretty good, and more accurate than using a timer. And can also deal with variable delays fed from a list.
 
Last edited:
Upvote 0
Top