不使用广播接收器处理从Alarm Manager发送的IntentServices时,是否需要获取唤醒锁?

时间:2012-08-23 14:34:05

标签: android intentservice wakelock

我一直在阅读有关从BroadcastReceiver启动服务的内容。在这种情况下,我必须获取一个WakeLock,直到Intent由IntentService处理。

当我直接从包含在pendingIntent中的AlarmManager调用IntentService时怎么样?在这种情况下,没有BroadcastReceiver ...意图直接转发到服务的onHandleIntent。那么,我在哪里获得锁?真的需要???一切似乎都很好。

1 个答案:

答案 0 :(得分:1)

IntentService只是一个线程服务。你需要获得一个唤醒锁。 Commonsguy有一个可爱的WakefulIntentService here

他的IntentService为你获取了一个Wakelock,所以如果你从一个AlarmService调用它,它将唤醒获取唤醒并在工作完成后释放它。

我已经使用它分配,效果很好,源代码在Github上,所以你可以看到它是如何工作的。