moxide moxide - 3 months ago 20
Android Question

Going Fullscreen Through MainActivity Crashes the App

When I try to make my app full-screen within MainActivity.java, my application is getting crashed. This is what my full screen code is:

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);

}

Answer

You are calling setContentView two times

//setContentView(R.layout.activity_main); //don't call here

requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
        WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
Comments