IntentService和AlarmManager通信 [英] IntentService and AlarmManager communication
问题描述
应该报警管理器发送的PendingIntent到IntentService还是更将其发送到广播接收器,然后发出startService()针对未决的意图是什么?
Should alarm manager send PendingIntent to IntentService or is it better to send it to a broadcast receiver which then issues startService() targeting the pending intent?
推荐答案
这取决于这是否是一个 _WAKEUP
报警或不是有点。
That depends a bit on whether this is a _WAKEUP
alarm or not.
如果没有,随意使用的getService()
的PendingIntent
。
If not, feel free to use a getService()
PendingIntent
.
如果,但是,它是一个 _WAKEUP
报警,你不仅需要使用广播接收器
中介,但广播接收器
还必须获取激活锁定
其中 IntentService
更高版本。在广播接收器
要求是由于方式 AlarmManager
处理自己的激活锁定
。我已经包裹所有这一切都成一个 WakefulIntentService
简化实施
If, however, it is a _WAKEUP
alarm, not only do you need to use a BroadcastReceiver
intermediary, but that BroadcastReceiver
must also acquire a WakeLock
which the IntentService
later releases. The BroadcastReceiver
requirement is due to the way AlarmManager
handles its own WakeLock
. I have wrapped all of this up as a WakefulIntentService
to simplify the implementation.
这篇关于IntentService和AlarmManager通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!