Normally, people don't use the wakelock facility as this requires that you give your app an additional permission, and it is very easy to introduce bugs where you accidentally remain holding the wake lock and thus leave the screen on. Hence it is better to use the window flag FLAG_KEEP_SCREEN_ON
, which you can enable on your activity's window .
Another solution is to add android:keepScreenOn="true"
(documentation) to the views that need to keep the screen on. This will allow you for a little bit more granular control in terms of which views stay on and which don't. You can even reference a setting from a resource file this way.
A related method setKeepScreenOn(true)
can be used for this purpose as well .