不同的情况下使用AlarmManager VS处理器的Android [英] different situations to use AlarmManager vs Handler Android
问题描述
有人能解释我不同的情况下使用AlarmManager VS处理程序的例子吧。使用这两个作为候补对方的任何缺点?
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?
感谢。
推荐答案
他们几乎没有什么关系吧。我假设你指的是使用类似 postDelayed()
在处理程序
轮询,这只是一个小功能对处理程序
。
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
.
您会使用 postDelayed()
(也可在查看
的任何部件或其他子类)的一个活动为简单定时事件是活动本身内的
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.
您会使用 AlarmManager
定期后台操作,就像你会使用的cron
中的Linux / OS X或在Windows计划任务。例如,如果你在写一个电子邮件客户端,你可以使用 AlarmManager
来触发你的code调用邮件服务器并检查新邮件。用户可以选择邮件检查频率,这将决定如何频繁 AlarmManager
将触发您code。
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.
这篇关于不同的情况下使用AlarmManager VS处理器的Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!