different situations to use AlarmManager vs Handler Android

China☆狼群 提交于 2019-12-04 10:20:34

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.

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