Keep the screen on

3 votes · 1 comment

You could keep the screen on if set the flag FLAG_KEEP_SCREEN_ON for your Activity. You also could use XML attribute android:keepScreenOn for different Views.

raw ·
copy
· download
First method: TestActivity.java public class TestActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); UtilSystem.setKeepScreenOn(this, true); } //... public void setKeepScreenOn(Activity activity, boolean keepScreenOn) { if(keepScreenOn) { activity.getWindow(). addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); } else { activity.getWindow(). clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); } } } // Second method: main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android = "http://schemas.android.com/apk/res/android" android:keepScreenOn = "true" android:orientation = "vertical" android:layout_width = "fill_parent" android:layout_height = "fill_parent"> <!-- ... --> </LinearLayout>
Add a comment

1 Comment

Reply · March 29, 2011, 3:57 p.m.