1

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();
    }
Paruyr
  • 37
  • 1
  • 8
  • for dealing with lifecycle-events in a better and elegant way use `viewmodels`, take a look at the [official docs](https://developer.android.com/topic/libraries/architecture/viewmodel) for more info – Sekiro Jan 11 '21 at 15:33
  • @rcs if you mean deleting android:configChanges in manifest and working with the lifecycle the issue is the same lifecycle event are not called when rotating 180 degree from landscape to reverse landscape – Paruyr Jan 11 '21 at 16:15

2 Answers2

1

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

laalto
  • 150,114
  • 66
  • 286
  • 303
  • 1
    this not solved my issue, onConfigurationChanged is not called, layout/view is rotating automatically. however I cannot handle events, i can only handle rotation from portrait to landscape 180 degree rotation doesn't call callback – Paruyr Jan 11 '21 at 15:55
0

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);
vimuth
  • 5,064
  • 33
  • 79
  • 116
UgurBH
  • 1
  • 1