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.
To release the wake lock, call wakelock. release() . This releases your claim to the CPU.
Wakelocks are power-managing software mechanisms, which make sure that your Android device doesn't go into deep sleep (which is the state that you should strive for), because a given app needs to use your system resources.
This feature can also be used to lock your phone—double-tap to lock, double-tap to unlock. Alternatively, if double-tapping your screen to lock and unlock your Android still isn't working, you can use a third-party app like Screen Off. Screen Off adds a handy shortcut on your phone's home screen.
The Screen Wake Lock API provides a way to prevent devices from dimming or locking the screen when an application needs to keep running.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With