title: Child fragment gets destroyed for no good reason
body: <p><strong>Info:</strong> I have a 2 pane layout (2 child <code>Fragments</code>) inside a <code>ParentFragment</code>, which, of course, is inside a <code>FragmentActivity</code>. I have <code>setRetainInstance(true)</code> on the <code>ParentFragment</code>. On orientation change, the <strong>left</strong> child fragment <strong>doesn't get</strong> destroyed (<code>onCreate()</code> doesn't get called), which is normal (because of the parent retaining its instance).</p>
  
  <p><strong>Problem:</strong> On orientation change, the <strong>right</strong> fragment <strong>gets</strong> destroyed (<code>onCreate()</code> gets called). Why the hell is the right fragment destroyed and the left one isn't ?</p>
  
  <p><strong>EDIT:</strong> If I remove <code>setRetainInstance(true)</code>, then the <strong>left</strong> fragment's <code>onCreate()</code> gets called <strong>twice</strong> (lol wtf) and the <strong>right</strong> fragment's <code>onCreate()</code> gets called once. So this isn't good either...</p>
  
  <p><strong>Code below for the ParentFragment:</strong></p>
  
  <pre><code>@Override
  public void onCreate(Bundle savedInstanceState)
  {
      super.onCreate(savedInstanceState);
      this.setRetainInstance(true);
  }
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
          Bundle savedInstanceState)
  {
      View view = inflater.inflate(R.layout.fragment_schedule, container, false);
      setHasOptionsMenu(true);
  
  
      if (getChildFragmentManager().findFragmentById(R.id.fragment_schedule_framelayout_left) == null || 
              !getChildFragmentManager().findFragmentById(R.id.fragment_schedule_framelayout_left).isInLayout())
      {
          if (mPresentationsListFragment == null)
              mPresentationsListFragment = PresentationsListFragment.newInstance(PresentationsListFragment.TYPE_SCHEDULE, mScheduleDate);
          getChildFragmentManager().beginTransaction()
                                       .replace(R.id.fragment_schedule_framelayout_left, mPresentationsListFragment)
                                       .commit();
      }
      mPresentationsListFragment.setOnPresentationClickListener(this);
  
  
      return view;
  }
  
  
  @Override
      public void onPresentationClick(int id)
      {
          if (Application.isDeviceTablet(getActivity()))
          {
              if (getChildFragmentManager().findFragmentById(R.id.fragment_schedule_framelayout_right) == null)
              {
                  if (mPresentationDetailFragment == null)
                      mPresentationDetailFragment = PresentationDetailFragment.newInstance(id);
                  else
                      mPresentationDetailFragment.loadPresentation(id);
                  getChildFragmentManager().beginTransaction()
                                             .replace(R.id.fragment_schedule_framelayout_right, mPresentationDetailFragment)
                                             .commit();
              }
              else
                  mPresentationDetailFragment.loadPresentation(id);
          }
          else
          {
              Intent presentationDetailIntent = new Intent(getActivity(), PresentationDetailActivity.class);
              presentationDetailIntent.putExtra(PresentationDetailActivity.KEY_PRESENTATION_ID, id);
              startActivity(presentationDetailIntent);
          }
      }
  </code></pre>
  
  <p><strong>LE Solution:</strong>
  Thanks a lot to <strong><em>antonyt</em></strong> , the answer is below. The only changes needed to pe performed reside inside onCreateView() of the parent <code>Fragment</code>.</p>
  
  <pre><code>@Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
          Bundle savedInstanceState)
  {
      View view = inflater.inflate(R.layout.fragment_schedule, container, false);
      setHasOptionsMenu(true);
  
  
      if (getChildFragmentManager().findFragmentById(R.id.fragment_presentations_framelayout_left) == null)
      {
          mPresentationsListFragment = PresentationsListFragment.newInstance();
          mPresentationsListFragment.setOnPresentationClickListener(this);
          getChildFragmentManager().beginTransaction()
                  .add(R.id.fragment_presentations_framelayout_left, mPresentationsListFragment)
                  .commit();
      }
  
  
      return view;
  }
  </code></pre>