BroadcastReceiver的,服务和WakelockBroadcastReceiver、Wakelock

2023-09-07 08:53:42 作者:保安大队长

即时接收广播接收机的意图,然后我开始服务做更多的工作。现在如果该设备是睡觉,这一点,我一定要得到Wakelock(AlarmManger?),为什么我需要它? 请问我的服务将停止运行,如果该设备不用得到一个wakelock睡觉。

解决方案   

现在,如果该设备是睡眠,这种情况发生,我一定要得到Wakelock(AlarmManger?),为什么我需要它?

如果该设备是睡着了,首先,你会不会接收广播接收机的意图,因为该设备是睡着了。

  

我一定要得到Wakelock(AlarmManger?),为什么我需要它?

您不需要,除非你想确保当你完成一些工作,保持运行的装置。

  

做我的服务将停止运行,如果该设备不用得到一个wakelock睡觉。

是的。

broadcastReceiver

im receiving an intent in broadcast receiver and then i start service to do more work. now what if the device is sleep and this happen, do i have to get Wakelock (AlarmManger?), and why do i need it? does my service will stop running if the device goes to sleep without getting a wakelock.

解决方案

now what if the device is sleep and this happen, do i have to get Wakelock (AlarmManger?), and why do i need it?

If the device is asleep to begin with, you will not be "receiving an intent in broadcast receiver", because the device is asleep.

do i have to get Wakelock (AlarmManger?), and why do i need it?

You don't "need it", unless you want to ensure the device stays running while you complete some work.

does my service will stop running if the device goes to sleep without getting a wakelock.

Yes.