How to release tracking lock?

I set the lock using wl.acquire() . It works great. I need this lock while waiting for my application to live, so the release() call can only be made when the application is left.

Do I need to call release() somewhere? For example, in onStop() ? I would say no, but I'm not sure.

Thanks A.

+4
source share
3 answers

Besides the other helpful answers you already received, I just found this interesting answer on how to make the screen , maybe you will find it useful if you really do not need tracking lock.

+4
source

if you link 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 must release the tracking lock as soon as you can: therefore, if your application closes / pauses its release!

Also, a word of advice, make sure you need a tracking lock when you need it and for a long time.

in my case, I only put it on the game screen to avoid the user’s screen going black thinking (since this opengl application only takes a few seconds to fully load), but in other views I release it.

Trust me when I say that annoying the user to end up with an empty battery, because the application forced itself to stay awake.

+4
source

as long as my application works how many actions does your application have? you can release it in onDestroy () of the last action that is called by the activitymanager agent.

And yes, you must release the lock, especially if you intend to maintain the brightness of the screen to avoid battery drain.

0
source

Source: https://habr.com/ru/post/1337109/


All Articles