I know that this question has been asked a lot of times but it has never been answered satisfactorily.
My problem is the following:
I have an activity which
Seems like it isn't possible to turn off the screen AND reactivate just by touching the display.
My new approach now:
private WakeLock screenWakeLock;
PowerManager pm = PowerManager.getSystemService(Context.POWER_SERVICE);
screenWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
"screenWakeLock");
screenWakeLock.acquire();
The PARTIAL_WAKE_LOCK keeps the CPU running but allows the display to shut down.
When power or home button is pressed the display turns on again and the activity becomes visible again (without having to "slide-to-unlock" or sth. else).
Don't forget to release the screenWakeLock
.
In my case I did it in the onResume()
of the activity:
if (screenWakeLock != null) {
if(screenWakeLock.isHeld())
screenWakeLock.release();
screenWakeLock = null;
}
Maybe this helps someone with a similar problem in the future.