Note that there are some explanatory texts on larger screens.

plurals
  1. POAdding Fragments to a LinearLayout programmatically
    text
    copied!<p>I am trying to add nested child Fragments into a parent Fragment.</p> <p>All works fine but....</p> <p>At first my code:</p> <pre><code>public class FragmentDatasheetWithHeader extends Fragment { private long mRowId; private String mSid; @Override public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) { final ScrollView scrollView = new ScrollView(getActivity()); final LinearLayout linearLayout = new LinearLayout(getActivity()); linearLayout.setId(4711); linearLayout.setOrientation(LinearLayout.VERTICAL); scrollView.addView(linearLayout); createUI(); return scrollView; } private void createUI() { final FragmentProductDetailHeader fragmentHeader = FragmentProductDetailHeader.newInstance(this.mRowId, FragmentProductDetailHeader.HEADERTYPE_SMALL); final FragmentDatasheet fragmentDatasheet = FragmentDatasheet.newInstance(this.mRowId, this.mSid); final FragmentManager fragmentManager = getChildFragmentManager(); fragmentManager.beginTransaction().add(4711, fragmentHeader, "fragmentHeader").commit(); fragmentManager.beginTransaction().add(4711, fragmentDatasheet, "fragmentDatasheet").commit(); } } </code></pre> <p>Now my problem:</p> <p>In the Developer options I activated "Don't keep activities (Destroy every activity as soon the user leaves it)"</p> <p>When the activity with the FragmentDatasheetWithHeader is open and the app goes into background and comes back to foreground the nested Fragments are doubled. But it only appears if the container for the nested Fragments is a LinearLayout. If the container is a FrameLayout the nested Fragments are not doubled.</p> <p>What's going wrong?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload