How handle Android Device 180 degree rotation (reverseLandscape)? - onConfigurationChanged is not called

1k Views Asked by At

When rotating phone 180 degree onConfigurationChanged Callback is not called, only works when changing rotation from portrait to landscape and vice verse, however rotating 180 degree when on landscape view is rotated however onConfigurationChanged callback is not called. How to handle 180 rotating.

my Manifest

<activity
            android:name="com.myApp.Activity"
            android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"/>

my Activity

@Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        Toast.makeText(this, "rotated", Toast.LENGTH_SHORT).show();
    }
2

There are 2 best solutions below

1
laalto On

The default screenOrientation mode behavior is vendor and device specific. For phones, it's typical that only -90°, 0° and 90° are supported.

To support all orientations, add android:screenOrientation="fullSensor" to your activity's manifest entry.

Docs: https://developer.android.com/guide/topics/manifest/activity-element#screen

0
UgurBH On

Kind of late answer but it may help in the future.

Call setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR) in your main activity's onCreate method.

Below works for me.

MainActivity.this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR);