Android:唤醒锁:应用程序暂停时锁是否被释放?

发布于 2024-11-27 19:09:22 字数 332 浏览 3 评论 0原文

我必须使用唤醒锁(是的,出于明显的原因,我不应该使用唤醒锁,但我是付费这样做的,所以我没有选择,哈哈)

我的问题很简单:当我让应用程序处于暂停或停止状态时,应用程序的唤醒锁是否自动释放?

我想避免用户关闭他的应用程序并且唤醒锁由于某种奇怪的原因仍然处于打开状态。

我当前的系统遇到问题,应用程序通过消息处理程序调用释放唤醒锁(因为它来自另一个线程),并且这种情况发生“太晚了”并且应用程序崩溃,因为它不再具有引用唤醒锁。

我可能不是很清楚,但这里的主要问题是:

我是否必须担心应用程序的唤醒锁会影响应用程序生命周期之外的手机。

干杯

杰森

I have to use the wakelock (yes I shouldn't for the obvious reasons but I'm being paid to do it so I don't have a choice lol)

my question is very simple: when I leave the app onPause or onStop, is the wake lock of the app automatically released ?

I want to avoid the user closing his app and the wake lock is still on for some weird reason.

I'm having an issue with my current system where the app is calling up the release wake lock through a message handler (because its coming from another thread) and this happens "too late" and the app crashes because it does no longer have the reference to the wake lock.

I might not be very clear but the main question here is :

do I have to worry about the wake lock of my app affecting the phone outside the life cycle of the app.

cheers

Jason

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

我也只是我 2024-12-04 19:09:22

我的问题很简单:当我让应用处于暂停或停止状态时,应用的唤醒锁是否会自动释放?

没有。这就是为什么您应该在活动中使用 android:keepScreenOn 而不是 WakeLock

我是否需要担心应用程序的唤醒锁会在应用程序的生命周期之外影响手机。

绝对地。在您释放 WakeLock 之前,手机不会进入睡眠状态。

my question is very simple: when I leave the app onPause or onStop, is the wake lock of the app automatically released ?

Nope. Which is why you should use android:keepScreenOn in an activity rather than a WakeLock.

do I have to worry about the wake lock of my app affecting the phone outside the life cycle of the app.

Absolutely. Until you release that WakeLock, the phone will not fall asleep.

笙痞 2024-12-04 19:09:22

即使您的应用程序不在前台,唤醒锁也肯定会影响您的设备!

这实际上是获取唤醒锁的全部意义

因此,请确保仅在没有其他选择时才使用唤醒锁,如果您的应用程序在后台时不需要唤醒锁,请确保在 onPause( ) 方法 !

这将极大地影响您的设备的性能和电池!

Wake lock DEFINITELY affects your device even if you application is NOT in foreground !

That's actually the whole point of acquiring wake locks

So, make sure you ONLY use wake locks when you have no other option, and if you don't need wake lock when your app is in background, make sure to release wake lock in onPause() method !

This will drastically affect your device 's performance and BATTERY !

素年丶 2024-12-04 19:09:22

当您的应用程序不再成为焦点时,唤醒锁就会被取消,只有当您的应用程序成为焦点时,唤醒锁才会生效。

When your application is no longer the focus the wake lock is cancelled, only when your application is the focus is the wake lock in affect.

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