Android Onconfigurationchanged Not Being Called

onConfigurationChanged not getting called

The problem was that if you use this method

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

to force the orientation of your Activity to portrait mode, you're not candidate to receive orientation changes.

So the solution is to not setRequestOrientation to a particular mode. But instead use SCREEN_ORIENTATION_SENSOR.

Android onConfigurationChanged not being called

A couple of things to try:

android:configChanges="orientation|keyboardHidden|screenSize" rather than android:configChanges="orientation"

Ensure that you are not calling setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); anywhere. This will cause onConfigurationChange() to not fire.

Check that you are not using android:screenOrientation in your manifest.

If none of that works, read through the Android doc on handling runtime changes and make sure you are doing everything correctly. There may be something somewhere else in your code that's causing the problem. http://developer.android.com/guide/topics/resources/runtime-changes.html

EDIT: As derrik pointed out, I assumed that you were changing the configuration with the accelerometer detecting what way the device was facing. If you want the configuration to change as the keyboard is shown/hidden the configChanges in the manifest must include keyboardHidden as well.

Why isn't onConfigurationChanged being called?

Use this code to get the confi chage

override fun onConfigurationChanged(newConfig: Configuration?) {
super.onConfigurationChanged(newConfig)
if (newConfig != null) {
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
Toast.makeText(this, "landscape", Toast.LENGTH_SHORT).show();
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
Toast.makeText(this, "portrait", Toast.LENGTH_SHORT).show();
}
}
}

A couple of things to try:

android:configChanges="orientation|keyboardHidden|screenSize" rather than android:configChanges="orientation"

Ensure that you are not calling setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); anywhere. This will cause onConfigurationChange() to not fire.

onConfigurationChanged not called anymore

From Honeycomb onwards you need also screenSize:

android:configChanges="orientation|keyboardHidden|screenSize"

onConfigurationChanged() is not being called on orientation change

If you create two different types of view (for landscape and portrait) in xml and you have to write logic on different types of view then donot use android:configChanges in manifest.

If you have no android:configChanges in manifest and you have different sets of layout for landscape and portrait then when you change orientation your control will come to onCreate() inside that method you can write your logic.

Android onConfigurationChanged() is not being called in Activity

The only thing that worked was using getLastNonConfigurationInstance(). http://developer.android.com/reference/android/app/Activity.html#getLastNonConfigurationInstance()

onConfigurationChanged not getting called even with manifest config changes - Why?

The onConfigurationChanged method is called when you physically rotated an Android device. So, you need to rotate your device to see the method gets called.

Note: The onConfigurationChanged also gets called when you changed locale, etc. See here for more info.

Also, I would have these values for the android:configChanges directive:

android:configChanges="orientation|screenSize|layoutDirection

Also, Issue 61671 might be related to the screen orientation problem described in this post. As of April 2014, this defect / bug has not been resolved by Google.

WORKAROUND

As stated in this SO link, screen orientation might work if the device type is set as a generic 7" tablet instead of Nexus 7.



Related Topics



Leave a reply



Submit