警报管理器,使用唤醒锁来确保所有代码运行
我正在考虑使用警报管理器,并在开发人员文档中阅读了此内容,但我不太明白。
"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() 来打开另一个线程,因此原始线程可以在服务可用之前完成其工作?
谢谢
I'm looking at using the Alarm Manager, and read this in the developer docs, which I don't really understand.
"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."
I am specifically asking for which situations it could possible that the phone will sleep before the service is launched (as this is the part I don't comprehend)? Is it dependent on how fast the phone can execute statements? ie. it calls startService() which opens another thread and so the original thread could complete its work before the service has been made available?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您从 BroadcastReceiver 启动服务,则只能保证设备在接收器的 onReceive() 期间不会休眠。根据这个问题,startService()是异步的,这意味着它不会阻止onReceive()完成当服务正在启动时。所以如果你需要确保服务启动,你必须实现自己的WakeLock。
If you're starting the service from a BroadcastReceiver, you're only guaranteed that the device will not sleep during the receiver's onReceive(). According to this question, startService() is asynchronous, which means it will not block onReceive() from finishing while the service is being started. So if you need to make sure that the service starts, you have to implement your own WakeLock.