如何释放唤醒锁?
我正在使用 wl.acquire() 设置唤醒锁。这很好用。只要我的应用程序存在,我就需要唤醒锁,因此只能在应用程序离开时调用 release()
。
我是否必须在某个地方调用 release()
?例如在 onStop()
中?我会说不,但我不确定。
I am setting a wake lock using wl.acquire()
. This works fine. I need that wake lock as long as my application lives, so calling release()
can only be done when the application is left.
Do I have to call release()
somewhere? For example in onStop()
? I would say no, but I am not sure.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您参考这两个页面:
http://developer.android.com/参考/android/os/PowerManager.html
http: //developer.android.com/reference/android/os/PowerManager.WakeLock.html#release()
您应该尽快释放唤醒锁:因此,如果您的应用程序正在关闭/暂停,请释放它!
另外,我的建议是,绝对确保您需要唤醒锁,当您需要它时,并且持续很长时间。
就我而言,我仅在游戏屏幕中放置一个,以避免用户在思考时屏幕变黑(因为它是一个 opengl 应用程序,需要几秒钟才能完全加载),但在其他视图中我释放了它。
相信我,当我说用户因为应用程序强迫自己保持唤醒状态而导致电池电量耗尽时,这很烦人。
if you refer yourself to these 2 pages:
http://developer.android.com/reference/android/os/PowerManager.html
http://developer.android.com/reference/android/os/PowerManager.WakeLock.html#release()
You should release the wake lock as soon as you can: therefore if your app is closing/pausing release it!
Also, word of advice, make absolutely sure you need a wake lock, when you need it and for ho long.
in my case I put one only for the in game screen to avoid the users screen going black while thinking (since it is an opengl app it takes a few seconds to fully load), but in the other views I release it.
Trust me when I say that it is annoying for a user to end up with a empty battery because an app was forcing itself to stay awake.
除了您已经收到的其他有用答案之外,我刚刚发现了一个关于如何强制屏幕打开的有趣答案,如果您确实不需要唤醒锁,也许您也会发现它很有用。
Beside the others useful answers you already received, I just found this interesting answer about how to force screen on, maybe you'll find it useful too, if you don't really need a wake lock.
是的,您必须释放锁定,特别是如果您要保持屏幕亮度,以避免电池耗尽。
And yes, you must release the lock especially if you are going to keep the screen brightness on, to avoid battery drain.