Are there any major differences between CountDownTimer and AlarmManager? I don't mean syntax or how to use it but wondering if there are such tasks when you certainly can say that I should use one of them, not another?
Simple example, I have to launch some action once a minute. What should I use? CountDownTimer or AlarmManager? How it depends?
AlarmManager
generally is used for purposes where your application is closed or must execute some repeating task(s). It is also slightly less precise than Timer
or Handler
.
CountDownTimer
is used more for running a specific task at a duration (onFinish
), and being updated periodically until it executes (onTick
).
In your specific case, I believe you should be using AlarmManager
, since it can repeat indefinitely. If you want something to execute every second for 10 seconds, for example, use CountDownTimer
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With