I have an activity that contains a linear layout and a fragment placeholder.
<RelativeLayout >
<LinearLayout/>
<fragment />
</RelativeLayout>
In onCreate() for the activity I place a fragment in the fragment placeholder and multiple fragments in the linear layout. This works fine until the phone goes through a configuration change (e.g. orientation change).
I do nothing special for an orientation or configuration change. What happens is really strange: the fragment placeholder is populated correctly but the linear layout now contains duplicate fragments. i.e. if the linear layout had fragment1 and fragment2 in it before, it will now show fragment1 fragment2 fragment1 fragment2. What is going on here?
As an additional note: I am using reflection to create the fragment objects, but I don’t think that should change anything.
The framework will automatically add the fragments to your view when the orientation is changed. Only execute the add fragment transactions when the paramBundle is null.
Example (using support library):