我正在考虑使用Alarm Manager,并在开发人员文档中阅读,我并不理解。
"If your alarm receiver called Context.startService(),
it is possible that the phone will sleep before the
requested service is launched. To prevent this, your
BroadcastReceiver and Service will need to implement a
separate wake lock policy to ensure that the phone
continues running until the service becomes available."
我特别询问哪些情况下手机可能会在服务启动前睡觉(因为这是我不理解的部分)?它取决于手机执行语句的速度有多快?即。它调用startService()来打开另一个线程,因此原始线程可以在服务可用之前完成其工作吗?
由于
答案 0 :(得分:1)
如果您从BroadcastReceiver启动服务,则只能保证设备在接收者的onReceive()期间不会休眠。根据{{3}},startService()是异步的,这意味着它不会阻止onReceive()在启动服务时完成。因此,如果您需要确保服务启动,则必须实现自己的WakeLock。