This morning I came up with a problem trying to handle the
onConfigurationChanged event. The problem is that the method, which I override, is not getting called when I change the orientation of the phone. Not getting called at all.
android:configChanges="orientation" on the activity defined in the manifest as mentioned on the android documentation, but this don’t make a difference.
Have you come up with this problem?
This was my gremlin for the ~same problem:
Caution: Beginning with Android 3.2 (API level 13), the “screen size”
also changes when the device switches between portrait and landscape
orientation. Thus, if you want to prevent runtime restarts due to
orientation change when developing for API level 13 or higher (as
declared by the minSdkVersion and targetSdkVersion attributes), you
must include the “screenSize” value in addition to the “orientation”
value. That is, you must decalare
android:configChanges=”orientation|screenSize”. However, if your
application targets API level 12 or lower, then your activity always
handles this configuration change itself (this configuration change
does not restart your activity, even when running on an Android 3.2 or
TL;DR: add “|screenSize” to configChanges when targeting API level 13+
Some devices of 4.0 doesn’t call onConfigurationChanged. Just add a listener to screenSize too.
The problem was that if you use this method
to force the orientation of your
Activity to portrait mode, you’re not candidate to receive
So the solution is to not
setRequestOrientation to a particular mode. But instead use
check that your device has “Screen rotation” setting ON
- Check that you are not using
Activityor in a
- Try using
I spent tens of minutes to find out why it did not work. I added
screenSize but it still did not work.
It turned out that I had added
android:configChanges to the
<application> element, not to the
<activity> element as I should have!
Well, of course, this was my mistake, but we all know that all of us spend a lot of time for this kind of silly mistake. So, I am adding this answer just in case there should be another silly programmer like me.
Macarse is 100% on the money with his 2nd option.
I had exactly the same issue, and on the 1.6 emulator adding
onConfigurationChanged to be called during rotation. Remove it and it stops being called.
I had the same problem –
onConfigurationChanged was not called when the device changed orientation despite having
android:configChanges="orientation|keyboardHidden" in the manifest file. I used the snipped of code shared by
to check if
onConfigurationChanged was being called. It was not.
After a few hours of experimenting, I realized that I had the following lines in the manifest file
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="15"/>
and on changing
onConfigurationChanged started being called. So, part of the manifest finally looked like this
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="8"/>
I just found that if you have :
in the manifest, onConfigurationChanged() will not be called too…
this may similar to:
that setting orientation block the onConfigurationChanged().
<uses-sdk android:minSdkVersion="8" android:maxSdkVersion="17" />
Dont use any target sdk versions to make you complication. and for all api levels use this as configuration change listener
Not sure this is the best place for it, but in encountering this issue – I observed something interesting.
If the onConfigurationChanged() listener is NOT working, then onCreate() is called again each time the orientation is changed.
If the onConfigurationChanged() listener is working, then that method is called instead of the onCreate() when orientation changes.
None of the suggestions worked for me (I had react native project with this issue), but after hours of debugging I found that if you have this line in the AppTheme of styles.xml
then the app will not rotate.
All solutions do not work util I try to remove my theme activity in Android manifest file. So strange
<activity android:name="MyActivity" android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation" android:theme="@style/MyTheme" --> remove this line /> <style name="MyTheme" parent="Theme.AppCompat.NoActionBar"> <item name="windowNoTitle">true</item> <item name="android:windowIsTranslucent">true</item> </style>
@thanhbinh84 Gave me an idea what could be causing this.
from my theme in styles.xml fixed it !
I had same issue and I had both “android:screenOrientation” and “android:configChanges” specified in manifest. When I removed first one, onConfigurationChanged() get called on rotation. Strange but it woks)
Have you got
android.content.res.Configuration in your import statements? Eclipse can insert imports automatically if you press
If that’s missing, the compiler will be unable to recognise that you’re legitimately overriding the superclass method and so will throw an error.