[ACCEPTED]-Android onConfigurationChanged not being called-orientation
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+
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.
Try use this one.....
android:configChanges="orientation|keyboardHidden|screenSize"
0
You should change the configChanges entry 4 in AndroidManifest.xml to:
android:configChanges="keyboardHidden|orientation"
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.
Add this to your manifest to each activity.
android:configChanges="keyboardHidden|orientation|screenSize"
Then, override 1 onConfigurationChanged
on your activity as such
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
}
Manifest:
<activity
android:name=".MainActivity"
android:configChanges="orientation|keyboardHidden|screenSize">
</activity>
Activity & Fragment:
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
Log.d(TAG, "onConfigurationChanged " +
(newConfig.orientation
== Configuration.ORIENTATION_LANDSCAPE
? "landscape" : "portrait"));
}
Output:
10-29 21:53:26.951 D/FragmentOne: onConfigurationChanged landscape 10-29 21:53:26.951 D/MainActivity:onConfigurationChanged landscape
0
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
.
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
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.