There are several mechanisms available for Android applications to stop the phone’s screen from being turned off. These methods override the default ‘screen timeout’ behaviour of your phone (typically found under
Settings -> Display), and will keep the screen on while your application is running.
I will be introducing two methods to stop the screen from being dimmed. The two methods provide means of accomplishing this depending on the current state of your application; i.e. whether it has an Activity on the foreground (visible on screen) or running on the background (as a Service).
- Use of
FLAG_KEEP_SCREEN_ONoption for your Activity.
- Use of a WakeLock.