I am having a problem with fragment ordering when the screen orientation changes during a custom animation of my fragment transition.
If I rotate the screen at exactly the right time, the fragments are added with the MyFragment2
in the position where MyFragment1
should be.
I am adding my fragments as follows:
final FragmentManager fm = activity.get().getFragmentManager();
final FragmentTransaction ft = fm.beginTransaction();
ft.setCustomAnimations(
R.animator.slide_in_left,
R.animator.slide_out_top,
R.animator.slide_in_bottom,
R.animator.slide_out_right);
ft.replace(R.id.container,
MyFragment1.newInstance(), MyFragment1.TAG);
ft.add(R.id.container,
MyFragment2.newInstance(),MyFragment12.TAG)
.addToBackStack(null)
.commit();
I have been searching for many hours for information about this problem. I have seen information here Android multiple fragment transaction ordering, here https://code.google.com/p/android/issues/detail?id=69403&thanks=69403&ts=1399482444 and here https://code.google.com/p/android/issues/detail?id=31116
My understanding is that this is a bug with re-adding fragments during onResume() of an activity.
How can I prevent my Activity from incorrectly ordering my fragments when it is resumed?
My Activity layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity"
tools:ignore="MergeRootFrame" />