I am just trying to adapt some of my applications for HoneyComb.
The issue iI am facing is the destruction of my activity on orientation change (landscape/portrait)
When I was using a classic activity, I wrote in the manifest:
But now, all these lines aren't working anymore!
Is there a workaround for that?
My code:
<activity android:name=".TwitterActivity" android:label="@string/app_name"
android:configChanges="keyboardHidden|orientation" />
<activity android:name=".TwitterActivity$AppListFragment"
android:configChanges="keyboardHidden|orientation" />
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 higher device).
Based on my experience with Honeycomb 3.0 and compatibility library (r1).
configChange="orientation"
does work with fragments with respect to preventing the activity (to which it is applied) being re-created on an orientation change. If you want thefragment
not to be re-created on activity re-creation then callsetRetainInstance
inonCreate
.Unless I'm missing something I don't quite get your second manifest entry, isn't
AppListFragment
aFragment
? If so then why is it listed as an entry in your manifest?See SO Answer for new qualifiers which is likely to be causing this if you are targetting sdk 13, suggest trying
android:configChanges="orientation|screenSize"
I was having this same problem (i.e., activity restarting) even without fragments.
I changed:
to:
That prevent the activity from restarting.
I had a very similar problem but had to make a couple of additions to get it to work with various version (including ICS).
In the main app activity I added a slightly different version of what Jason offered.
I had this working on pre-Honeycomb with:
I had to make the first example to get it running on all versions. I'm currently using fragments and ActionBarSherlock for backwards compatibility.
I also changed the way I was saving and reloading:
The code for the save instance state method:
Hope this helps.
Up to API 13 there was a new value to the configChanges attribute,
screenSize
So if you're using large screens make sure to add screenSize in your configChanges attribute:
I know this is quite late answer, but I recently faced this issue and was able to resolve this for Fragment Activity.
1) In Manifest,
2) In Class file, override the onSaveInstanceState(Bundle outState). Thats it! Enjoy :)