我正在编写一个Android客户端应用程序,它使用HTTP长轮询(Comet)继续从服务器接收推送通知.
我不想总是保留WakeLock,因为它会耗尽电池,但我需要确保设备即使在睡眠模式下也能收到通知.
我发现了这个问题:
其中"CommonsWare"提到非Wifi套接字上的传入数据包将唤醒设备.
所以我的解决方案如下所示:
Client ------------------------- Server
---- Request----->
release WakeLock (Allow device to sleep)
<----Notification-- (Hopes it can wake up the device)
require WakeLock
process the notification
---- Request----->
release WakeLock
....
Run Code Online (Sandbox Code Playgroud)
但是在接收通知和要求唤醒锁之间有一点时间窗口,所以我的问题是,设备保持这种清醒状态多长时间?在此时间窗口内,设备是否可以重新进入睡眠状态?