IntentService and AlarmManager communication

自古美人都是妖i 提交于 2019-12-12 15:16:06

问题


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?


回答1:


That depends a bit on whether this is a _WAKEUP alarm or not.

If not, feel free to use a getService() PendingIntent.

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.



来源:https://stackoverflow.com/questions/4982920/intentservice-and-alarmmanager-communication

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