Android:唤醒锁:应用程序暂停时锁是否被释放?
我必须使用唤醒锁(是的,出于明显的原因,我不应该使用唤醒锁,但我是付费这样做的,所以我没有选择,哈哈)
我的问题很简单:当我让应用程序处于暂停或停止状态时,应用程序的唤醒锁是否自动释放?
我想避免用户关闭他的应用程序并且唤醒锁由于某种奇怪的原因仍然处于打开状态。
我当前的系统遇到问题,应用程序通过消息处理程序调用释放唤醒锁(因为它来自另一个线程),并且这种情况发生“太晚了”并且应用程序崩溃,因为它不再具有引用唤醒锁。
我可能不是很清楚,但这里的主要问题是:
我是否必须担心应用程序的唤醒锁会影响应用程序生命周期之外的手机。
干杯
杰森
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
没有。这就是为什么您应该在活动中使用
android:keepScreenOn
而不是WakeLock
。绝对地。在您释放
WakeLock
之前,手机不会进入睡眠状态。Nope. Which is why you should use
android:keepScreenOn
in an activity rather than aWakeLock
.Absolutely. Until you release that
WakeLock
, the phone will not fall asleep.即使您的应用程序不在前台,唤醒锁也肯定会影响您的设备!
这实际上是获取唤醒锁的全部意义
因此,请确保仅在没有其他选择时才使用唤醒锁,如果您的应用程序在后台时不需要唤醒锁,请确保在 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 !
当您的应用程序不再成为焦点时,唤醒锁就会被取消,只有当您的应用程序成为焦点时,唤醒锁才会生效。
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.