0

I have to detect when the configuration has changed. I have put the configChanges conditions in the manifest

    <activity
        android:name=".WorkoutActivity"
        android:configChanges="orientation|keyboardHidden|screenSize">
    </activity>

There are no setRequestedOrientation in the activity or in any fragment. Here is the code for configuration change:

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    Toast.makeText(this, "activity rotated", Toast.LENGTH_SHORT).show();
}
suku
  • 10,507
  • 16
  • 75
  • 120

2 Answers2

0

The reason for the rotation not being detected was because I had set the device rotation to portrait (canceled autorotate) on my mobile phone. This prevented my app from rotating. Found the answer here: onConfigurationChanged not getting called

The way to override this preference set by the user is to add the following code to the manifest as answered here: onConfigurationChanged is not getting called any time in android

android:screenOrientation="sensor"

Now the app rotates based on the sensor input and onConfigurationChanged is triggered. I hope this answer helps others get rid of this potential bug.

Community
  • 1
  • 1
suku
  • 10,507
  • 16
  • 75
  • 120
0

Remove android:configChanges="orientation|keyboardHidden|screenSize">