如何释放唤醒锁?

发布于 2024-10-14 18:31:42 字数 180 浏览 2 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

小…楫夜泊 2024-10-21 18:31:42

如果您参考这两个页面:

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.

皓月长歌 2024-10-21 18:31:42

除了您已经收到的其他有用答案之外,我刚刚发现了一个关于如何强制屏幕打开的有趣答案,如果您确实不需要唤醒锁,也许您也会发现它很有用。

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.

自控 2024-10-21 18:31:42

只要我的应用程序存在
您的应用程序有多少活动?您可以在 ActivityManager 弹出的最后一个 Activity 的 onDestroy() 中释放它。

是的,您必须释放锁定,特别是如果您要保持屏幕亮度,以避免电池耗尽。

as long as my application lives
how many activities your application has? you can release it in onDestroy() of last activity that gets popped by activitymanager.

And yes, you must release the lock especially if you are going to keep the screen brightness on, to avoid battery drain.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文