Search code examples
androidandroid-layoutandroid-fragmentsandroid-orientationandroid-2.3-gingerbread

Screen Orientation Change Gingerbread Recreate Fragment


Friends,

I have an old device that is running Gingerbread. Whenever I change the orientation of the phone, my Fragment does not get destroyed and recreated, i.e., onDestory() and onCreate() are not called. This is not the default behaviour on devices running Android OS > Gingerbread.

My question is how do I force the fragment to recreate on devices running Gingerbread wehn the user changes oriatation from Portrait to Landscape and vice-versa.

In my manifest file I have:

 android:configChanges="keyboardHidden|orientation"

Thanks


Solution

  • It's cool you have added you rmanifest code because it is a bit wrong.

    On newer version of Android you need to add something :

    android:configChanges="keyboardHidden|orientation|screenSize"
    

    With that, orientation changes will be handle by your activity, your fragment will not be recreated on any version of Android. If you want your fragment to be recreated each time, you just need to remove that from the manifest.