Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top