different situations to use AlarmManager vs Handler Android

杀马特。学长 韩版系。学妹 提交于 2020-01-01 12:25:50

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/5448758/different-situations-to-use-alarmmanager-vs-handler-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!