In this video, we will learn how to keep the screen activated for a particular activity in our Android app, so it doesn’t automatically turn off after some time of inactivity.
We can do this in 2 ways, either by calling getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) in the activitie’s Java file, or by adding the android:keepScreenOn=”true” attribute to its XML layout file.
This is the alternative for the deprecated PowerManager.FULL_WAKE_LOCK.
With clearFlags we can remove a programmatically added screen-on flag, but even if we don’t remove it, the system will automatically release the flag if we switch to another window, for example when we open another activity or when we put the app into the background.
Subscribe to my channel:
Want more Android tutorials? Check my playlist section:
Follow me on social media: