I have an Activity that usually needs some time to watch the screen without interacting with it.
The problem is that the screen turns off, just like with almos any other app.
I want to prevent that automatic turn off for my Activity, like Dolphin HD does (if you configure it from the settings menu).
I want to let the user to turn off the screen pressing the usual block button, but prevent the automatic block of the device while in my Activity.
How can I achieve this?
Thanx.
Add
android:keepScreenOn="true"to some widget in your layout XML resource for this activity. So long as that widget is visible on the screen, the screen will not turn off automatically.EDIT:
A
WakeLock, as suggested by other answers, technically will work. But then you have to manually release theWakeLock(if you mess that up, the screen will stay on a long time). And, since you could mess it up, you need theWAKE_LOCKpermission. UsingkeepScreenOnavoids all of that.