我是否需要在 onReceive 方法中为 CONNECTIVITY_ACTION 广播保留 PARTIAL_WAKE_LOCK?
我有一个服务,它使用 ConnectivityManager.CONNECTIVITY_ACTION 意图过滤器侦听网络连接更改。我是否应该在 onReceive 方法开始时获取部分 cpu 锁来处理它?
I have a Service that listens to network connectivity changes using the ConnectivityManager.CONNECTIVITY_ACTION intent filter. Should I acquire a partial cpu lock at the beginning of my onReceive method to process it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你不需要为广播接收器本身保留唤醒锁,Android 会为你做这件事。
但如果您需要做任何持久的事情,您将需要在 onReceive 内生成一个新服务,此时您应该获取该服务的唤醒锁。
另请参阅文档,以确保只锁定真正需要的系统资源(主要是 cpu)http://developer.android.com/reference/android/os/PowerManager.html
you don't need to hold a wake lock for the broadcast receiver itself, android will do that for you.
But if you need to do anything long lasting, you will need to spawn a new service inside onReceive, at which time you should acquire a wake lock on the service.
also look at the documentation to make sure you only hold locks to system resources you really need (mostly just cpu) http://developer.android.com/reference/android/os/PowerManager.html