Saturday, January 28, 2012

Keep Screen On!

Sometimes you just want to keep the screen light on while the user is on a certain Activity.
Enter.. FLAG_KEEP_SCREEN_ON!

FLAG_KEEP_SCREEN_ON - "Window flag: as long as this window is visible to the user, keep the device's screen turned on and bright. "



Usage: 
A. Inside the onCreate() method of your Activity
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

or

B. In your layout xml
<RelativeLayout... android:keepScreenOn="true" />

As long as this Activity is shown to the user, the screen light will be on! Once the user moves over to another activity, the default screen timeout will kick-in.
No wake lock required!