开发者

Android: wake lock: is lock released on application paused?

开发者 https://www.devze.com 2023-03-24 11:17 出处:网络
I have to use the wakelock (yes I shouldn\'t for the obvious reaso开发者_开发问答ns but I\'m being paid to do it so I don\'t have a choice lol)

I have to use the wakelock (yes I shouldn't for the obvious reaso开发者_开发问答ns 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


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号