title: ViewPager Fragments missing after popBackStack
body: <p>I am having problems with fragments or maybe rather the way I want them to work.</p>
  
  <p>In my activity I have a layout container (R.id.container1) to which I add a fragment (FragMain) programmatically at startup.
  In the fragment I have 2 Fragments (Frag1, Frag2) and a ViewPager which loads several other fragments (FragA, FragB, FragC, FragD, FragE) via a FragmentPagerAdapter.</p>
  
  <p>On a button press I replace the whole content of R.id.container1, so FragMain is replaced with another Fragment (FragSub).
  Now when I press the back button, FragMain is loaded again, but the ViewPager isn't fully initialized, some Fragments are missing. From what I observed, it's always FragB and FragD missing, If I scroll to the empty views, the app crashes. The other fragments seem to be fine. What's going wrong here? </p>
  
  <p>This thread suggests using getChildFragmentManager in creation of the PagerAdapter, but I am already doing that... <a href="https://stackoverflow.com/questions/16600156/fragment-in-viewpager-not-restored-after-popbackstack">Fragment in ViewPager not restored after popBackStack</a></p>
  
  <p>I am accessing the fragments via e.g. </p>
  
  <pre><code>((FragA)((PagerAdapter)viewPager.getAdapter()).getItem(0));
  </code></pre>
  
  <p>Is this the best way? </p>
  
  <p>Some Code : </p>
  
  <p>MainActivity's onCreate</p>
  
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      pagerFragList = new Vector&lt;Fragment&gt;();
      pagerFragList.add(Fragment.instantiate(this, FragA.class.getName()));
      pagerFragList.add(Fragment.instantiate(this, FragB.class.getName()));
      pagerFragList.add(Fragment.instantiate(this, FragC.class.getName()));
      pagerFragList.add(Fragment.instantiate(this, FragD.class.getName()));
      pagerFragList.add(Fragment.instantiate(this, FragE.class.getName()));
  
      FragMain fragMain = (FragMain)getSupportFragmentManager().findFragmentByTag(FragMain.debugTag);
      if(fragMain==null) fragMain = new FragMain();
      FragmentHelper.replaceSupportFragment(this, fragMain, R.id.container1, false, FragMain);
  
  }
  </code></pre>
  
  <p>Helper</p>
  
  <pre><code>public Vector&lt;Fragment&gt; getFragList() {
      return pagerFragList;
  }
  </code></pre>
  
  <p>FragMain's onViewCreated</p>
  
  <pre><code>@Override
  public void onViewCreated(View view, Bundle savedInstanceState) {
      super.onViewCreated(view, savedInstanceState);
  
      pagerAdapter = new PagerAdapter(getChildFragmentManager(), ((MainActivity)getActivity()).getFragList());
      viewPager = ((ViewPager)view.findViewById(R.id.viewPager));
      viewPager.setAdapter(pagerAdapter);
      viewPager.setOffscreenPageLimit(5);
      viewPager.setCurrentItem(0, true);
  
  }
  </code></pre>
  
  <p>The PagerAdapter</p>
  
  <pre><code>public class PagerAdapter extends FragmentPagerAdapter {
  
  private List&lt;Fragment&gt; fragments;
  
  public PagerAdapter(FragmentManager fm, List&lt;Fragment&gt; fragments) {
      super(fm);
      this.fragments=fragments;
  }
  
  @Override
  public Fragment getItem(int position) {
      return fragments.get(position);
  }
  
  @Override
  public int getCount() {
      return fragments.size();
  }
  </code></pre>
  
  <p>}</p>