[ACCEPTED]-Android onConfigurationChanged not being called-orientation

Accepted answer
Score: 83

This was my gremlin for the ~same problem:

Caution: Beginning 18 with Android 3.2 (API level 13), the "screen 17 size" also changes when the device 16 switches between portrait and landscape orientation. Thus, if 15 you want to prevent runtime restarts due 14 to orientation change when developing 13 for API level 13 or higher (as declared 12 by the minSdkVersion and targetSdkVersion 11 attributes), you must include the "screenSize" value 10 in addition to the "orientation" value. That 9 is, you must decalare android:configChanges="orientation|screenSize". However, if 8 your application targets API level 12 7 or lower, then your activity always handles 6 this configuration change itself (this configuration 5 change does not restart your activity, even 4 when running on an Android 3.2 or higher 3 device).

(From http://developer.android.com/guide/topics/resources/runtime-changes.html)

TL;DR: add "|screenSize" to 2 android:configChanges="orientation" for 1 API 14+

Score: 64

A couple of things to try:

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

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

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

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

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

Score: 10

Try use this one.....



Score: 5

You should change the configChanges entry 4 in AndroidManifest.xml to:


Otherwise, sliding 3 the keyboard doesn't trigger onConfigurationChange() even 2 though the orientation changes. I just tested 1 this on my HTC Desire Z.

Score: 4

Add this to your manifest to each activity.


Then, override 1 onConfigurationChanged on your activity as such

public void onConfigurationChanged(Configuration newConfig) {
Score: 2



Activity & Fragment:

public void onConfigurationChanged(Configuration newConfig) {
    Log.d(TAG, "onConfigurationChanged  " +
                == Configuration.ORIENTATION_LANDSCAPE
                ? "landscape" : "portrait"));


10-29 21:53:26.951 D/FragmentOne: onConfigurationChanged landscape

10-29 21:53:26.951 D/MainActivity:onConfigurationChanged landscape


Score: 1

It wasn't triggering in my Fragment (Fragments aren't registered 2 in the AndroidManifest.xml) so I had to move it to the Activity managing 1 my Fragment, in my case the TabsPagerActivity.

Score: 0

Few things can be cross check:

In my case I was tracking language change of device using the onConfigurationChanged.

Few things 8 need to know about onConfigurationChanged 7 is there is some difference in behavious 6 between onConfigurationChanged of Activity 5 and Application.

When you change the configuration of device the Application level onConfigurationChanged will be call automatically and immediately but onConfigurationChanged of activity will call when you navigate to that activity.

and another thing is only 4 locale in manifest will not work sometime 3 So you have declare other config change 2 event along with the locale(in my case) that 1 should be like android:configChanges="layoutDirection|locale"

More Related questions