简体   繁体   English

Android - 使用LocationManager.requestLocationUpdates时,是否需要WakeLock?

[英]Android - When using LocationManager.requestLocationUpdates, do I need a WakeLock?

My app periodically checks the location using an alarm to a BroastcastReceiver that starts a service. 我的应用程序使用警报定期检查位置,以启动服务的BroastcastReceiver 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? 如果我在调用requestLocationUpdates后释放唤醒锁,设备是否可以进入休眠状态而不是调用我的LocationListener或者设备是否会一直唤醒以提供更新并保持清醒直到回调返回? 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. 我不愿意抓住唤醒锁,因为这会阻止设备在更新之间休眠,直到我完成该位置。

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. 所以根据我的经验(并在此处的评论中确认),在调用requestLocationUpdates之后释放唤醒锁似乎不是问题。 Unfortunately, the only way to get a definitive answer is to ask a platform developer, but I've received no response . 不幸的是,获得明确答案的唯一方法是询问平台开发人员,但我没有收到任何回复

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; 检查Android系统设置中的省电模式 :必须禁用它才能允许位置管理器在屏幕关闭时生成更新位置; tested on Samsung A5; 在三星A5上测试过; I took two days to find this solution :-) 我花了两天时间才找到这个解决方案:-)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 什么locationManager.requestLocationUpdates可以做什么? - What locationManager.requestLocationUpdates do? Android:使用LocationManager.requestLocationUpdates()时如何从intent bundle extras获取位置信息 - Android: How to get location information from intent bundle extras when using LocationManager.requestLocationUpdates() android LocationManager.requestLocationUpdates,minTime> 0无法按预期工作 - android LocationManager.requestLocationUpdates with minTime >0 not working as expected ANDROID locationManager.requestLocationUpdates无法解析? - ANDROID locationManager.requestLocationUpdates cannot be resolved? LocationManager.requestLocationUpdates是否添加或更新? - LocationManager.requestLocationUpdates add or update? Android:LocationManager.requestLocationUpdates不尊重params - Android: LocationManager.requestLocationUpdates doesn't respect params locationManager.requestLocationUpdates()导致NullpointerException - locationManager.requestLocationUpdates() results in NullpointerException 不适用于Android Studio- locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0,this); - Doesn't work on Android Studio- locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this); 缺少LocationManager.requestLocationUpdates所需的权限 - Missing permissions required by LocationManager.requestLocationUpdates 在后台正确处理LocationManager.requestLocationUpdates - Proper handling LocationManager.requestLocationUpdates in background
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM