Android - 使用 LocationManager.requestLocationUpdates 时,我需要 WakeLock 吗?
我的应用程序使用启动服务的 BroastcastReceiver
警报定期检查位置。我知道我应该在启动服务之前获取唤醒锁,但我的问题是我什么时候可以释放它?
如果我在调用 requestLocationUpdates
后释放唤醒锁,设备是否可以进入睡眠状态而不调用我的 LocationListener
,或者设备是否始终唤醒以提供更新并保持唤醒状态,直到回调完成回来了?我不愿意保留唤醒锁,因为这会阻止设备在更新之间休眠,直到我完成定位。
My app periodically checks the location using an alarm to a BroastcastReceiver
that starts a service. I know I should acquire a wakelock before I start the service but my question is when can I release it?
If I release the wakelock after calling requestLocationUpdates
, can the device go to sleep and not call my LocationListener
or will the device always wake to deliver updates and stay awake until the callback has returned? I'm reluctant to hold onto the wakelock because that would prevent the device from sleeping between updates until I'm done with the location.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
因此,根据我的经验(并在此处的评论中确认),在调用 requestLocationUpdates 后释放唤醒锁似乎不是问题。不幸的是,获得明确答案的唯一方法是询问平台开发人员,但我收到了 无响应。
So based on my experience (and confirmed in the comments here), releasing the wake lock after after calling
requestLocationUpdates
doesn't seem to be a problem. Unfortunately, the only way to get a definitive answer is to ask a platform developer, but I've received no response.检查Android系统设置中的省电模式:必须禁用它才能允许位置管理器在屏幕关闭时生成更新位置;在三星 A5 上进行测试;我花了两天时间才找到这个解决方案:-)
check for power saving mode in Android system settings: it must be disable to permit location manager to generate update location when the screen is off; tested on Samsung A5; I took two days to find this solution :-)