Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android timer swing

Tags:

android

timer

I need to create a Timer to update the UI at regular intervals. But the Swing Timer class is not available on Android. How can I work around this problem ? (I would avoid creating threads and then use the Timer class from java.util package)

like image 593
Arutha Avatar asked Nov 20 '25 09:11

Arutha


2 Answers

You could use a Handler and the postAtTime() method or the postDelayed() method. This will allow you to schedule a Runnable to be executed at some point in the future.

like image 62
Dave Webb Avatar answered Nov 21 '25 23:11

Dave Webb


Well, for your problem Handler class would suffice(+1 to Dave :)).
FYI, there are other classes namely AlarmManager, Timer & TimerTask that can help with timing the runs of your code.

like image 41
Samuh Avatar answered Nov 21 '25 21:11

Samuh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!