Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Keep the Screen On

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 115
    Comment on it

    There are certain situations when we need to turn screen ON such as live map games, routing, movie, tv apps.

    Basically, to avoid battery draining android device fall asleep after some time, but to accomplish this task we have to keep screen ON.

    We can do it from both Activity as well as from XML.

    From Activity:

    We use WindowManager class by using FLAG_KEEP_SCREEN_ON property.


     

    public class MainActivity extends Activity {
      @Override
      protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
      }

    From XML:

    By using keepScreenOn attribute

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:keepScreenOn="true">
        ...
    </RelativeLayout>

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: