Skip to content Skip to sidebar Skip to footer

Android Screen Orientation Change Causes App To Quit

I have an app that I set to only display in Portrait mode by setting android:screenOrientation='portrait' for each Activity in the manifest. This works fine and my app screen doe

Solution 1:

i would recommend to set the orientation inside your splash screen or the next activity programatically. Try to implement this code:

//get the WindowManager ServiceDisplaydisplay= ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
//get the orientationintorientation= display.getOrientation();
//orientation % 2 == 0 is portrait mode,if ((orientation % 2) != 0) (android.view.IWindowManager.Stub.asInterface(ServiceManager.getService("window"))).setOrientation(0);

I hope this will work.

Solution 2:

The application closes on orientation change because you must provide with particular resources in the res folder

  • Eg:layout-land in res folder or

handle the change at runtime through programmatically

@OverridepublicvoidonConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);

    // Checks the orientation of the screenif (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
        Toast.makeText(this, "landscape", Toast.LENGTH_SHORT).show();
    } elseif (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
        Toast.makeText(this, "portrait", Toast.LENGTH_SHORT).show();
    }
}

Post a Comment for "Android Screen Orientation Change Causes App To Quit"