Skip to content

Instantly share code, notes, and snippets.

@billmote
Created February 4, 2015 15:47
Show Gist options
  • Save billmote/06820b5c4051d700af9c to your computer and use it in GitHub Desktop.
Save billmote/06820b5c4051d700af9c to your computer and use it in GitHub Desktop.
Keep the screen on while the activity is visible.
public class KeepScreenOn extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_keepscreenon);
}
@Override
protected void onResume() {
super.onResume();
this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
@Override
protected void onPause() {
this.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
super.onPause();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment