In the following sample activity, the screen automatically wakes up right after the user switches it off (with power button), but only if I use the PowerManager.ON_AFTER_RELEASE flag. It doesn’t happen if I don’t use this flag.
public class TestActivity extends Activity {
private WakeLock wakeLock;
@Override
protected void onResume() {
super.onResume();
wakeLock = ((PowerManager) getSystemService(Context.POWER_SERVICE)).newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, "test");
wakeLock.acquire();
}
@Override
protected void onPause() {
wakeLock.release();
super.onPause();
}
}
Is there a way to avoid this behaviour while still using the PowerManager.ON_AFTER_RELEASE flag ?
I have the same issue when using the MediaPlayer’s setWakeMode() method (I checked in the source code and it also uses this PowerManager.ON_AFTER_RELEASE flag)
Or maybe I just misunderstand the purpose of this flag…what is it made for then ?
Ok, after many experiments it seems that there is no way to avoid this auto screen wakeup when using this
PowerManager.ON_AFTER_RELEASE.As a consequence it’s not possible to use
MediaPlayer.setWakeMode()without having this issue.