title: Proper use of sub sub fragments with (Child)FragmentManager
body: <p>How do I properly use Fragments in Fragments?</p>
  
  <p>My (simplified) use case is following, I have an activity with a layout fragment and this fragment theirself contains a sub fragment... all fragments are added manually to their parents...</p>
  
  <pre><code>----------------------------------------------------------
  - Activity                                               -
  -                                                        -
  -                                                        -
  -     ---------------------------------------            -
  -     - Fragment                            -            -
  -     -                                     -            -
  -     -    -----------------                -            -
  -     -    - SubFragment   -                -            -
  -     -    -               -                -            -
  -     -    -               -                -            -
  -     -    -----------------                -            -
  -     ---------------------------------------            -
  -                                                        -
  ----------------------------------------------------------
  </code></pre>
  
  <p>Now in my activity's <code>onCreate</code> I do following:</p>
  
  <pre><code>if (savedInstanceState == null)
  {
      // I create the fragment
      mMainFragment = new MainFragment();
      FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
      transaction.replace(R.id.fragment_main, mMainFragment);
      transaction.commit();
  }
  else
  {
      // I retrieve the fragment
      mMainFragment = (BaseFragment) getSupportFragmentManager().findFragmentById(R.id.fragment_main);
  }
  </code></pre>
  
  <p>And in my fragments <code>onCreate</code> I get/create my SubFragment:</p>
  
  <pre><code>mSubFragment = getChildFragmentManager().findFragmentByTag(SubFragment.class.getName());
  if (mSubFragment == null)
  {
      mSubFragment = new SubFragment();
      getChildFragmentManager().beginTransaction().add(R.id.fragment_sub, mSubFragment, SubFragment.class.getName()).commit();
  }
  </code></pre>
  
  <p><strong>Problem</strong></p>
  
  <p>After screen rotation, my SubFragment is added twice... If I use the activity's <code>FragmentManager</code> then it works... But why does it not work with the <code>ChildFragmentManager</code>? Of course, the Fragment is a new fragment, but the activity is a new one as well, so why does it work with the activity's <code>FragmentManager</code> but not with the parent fragment's one?</p>
  
  <p>In a fragment, I should use the fragments <code>ChildFragmentManager</code>, shouldn't I?</p>