I've got application which is playing TV streams and needs to be ON all the time. I do acquire wake lock in OnCreate()
pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
wl = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, TAG);
wl.acquire();
and then release in onDestroy()
if (wl != null) {
wl.release();
wl = null;
}
User usually minimize the app by pressing back, home or power button and then resumes from home screen tapping the app icon. I do release wake lock in onPause() and acquire in onResume().
Time to time I see application crashes or disappears completely from screen and I see logs related to wake lock.
Is this a best practice to control Android Power Manager Wake Lock?
Any opinions are welcome.
try this:
and dont forget permissions: