Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

different situations to use AlarmManager vs Handler Android

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.

like image 967
poddroid Avatar asked Dec 13 '22 14:12

poddroid


1 Answers

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.

like image 93
CommonsWare Avatar answered May 08 '23 03:05

CommonsWare