0

我正在考虑使用警报管理器,并在开发人员文档中阅读了这个,我不太明白。

"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."

我特别询问哪些情况下手机可能会在服务启动之前休眠(因为这是我不理解的部分)?是否取决于手机执行语句的速度?IE。它调用 startService() 打开另一个线程,因此原始线程可以在服务可用之前完成其工作?

谢谢

4

1 回答 1

1

如果您从广播接收器启动服务,您只能保证设备在接收器的 onReceive() 期间不会休眠。根据这个问题, startService() 是异步的,这意味着它不会在服务启动时阻止 onReceive() 完成。因此,如果您需要确保服务启动,您必须实现自己的 WakeLock。

于 2012-02-12T08:59:09.397 回答