Cemre Cemre - 1 year ago 76
Android Question

Android wake lock is not released

I get the wake lock like in

method and it works fine (I also set the permissions):

PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Wake lock");

However, when I try to release it like:

protected void onDestroy()

it is not released for some reason. How is this possible ? Any ideas ?

EDIT: I have an exit button which calls finish() which then calls onDestroy(). When I press the exit button and then put the phone to sleep I expect my program not to work but it works which shows me that the lock is not released

Answer Source

The right way to determine whether your WakeLock-releasing code works is to use adb shell dumpsys power, before and after the release, to see if your WakeLock is released. Since other apps can request and acquire WakeLocks whenever they want, other casual checks (e.g., does my app run when the screen is off?) will be unreliable.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download