Could someone explain me different situations to use AlarmManager vs Handler with examples please. Any disadvantages of using these two as alternate to each other?
Thanks.
They have little to do with one another. I am assuming you are referring to using something like postDelayed()
on Handler
for polling, which is but one small feature of Handler
.
You would use postDelayed()
(also available on any widget or other subclass of View
) in an activity for simple timing events that are within the activity itself.
You would use AlarmManager
for periodic background operations, much like you would use cron
in Linux/OS X or a Scheduled Task on Windows. For example, if you were writing an email client, you would use AlarmManager
to trigger your code that calls the mail server and checks for new messages. The user could choose the email-check frequency, which would determine how frequently AlarmManager
would trigger your code.
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