title: ViewPager's Fragment's view lost when ViewPager's parent Fragment hidden then shown
body: <p>I've been seeing some strange behavior with my ViewPager along with my own FragmentStatePagerAdapter.</p>
  
  <p>My View hierarchy goes like this:</p>
  
  <pre><code>-&gt; (1) Fragment root view (RelativeLayout)
   -&gt; (2) ViewPager
    -&gt; (3) ViewPager's current fragment view
  </code></pre>
  
  <p>When the Fragment that is responsible for the Fragment root view (1) gets hidden (using .hide() in a fragment transaction) and then shown (with .show()), the fragment view that was currently showing in the ViewPager (3) becomes null, although the fragment still exists.  Basically, my ViewPager becomes completely blank/transparent.</p>
  
  <p>The only way I have found to fix this is to call </p>
  
  <pre><code>int current = myViewPager.getCurrentItem();
  myViewPager.setAdapter(myAdapter);
  myViewPager.setCurrentItem(current);
  </code></pre>
  
  <p>after the parent fragment is shown.  This somehow triggers the views to be recreated and appear on screen.  Unfortunately, this occasionally causes exceptions dealing with the pager adapter calling <code>unregisterDataSetObserver()</code> twice on an old observer.</p>
  
  <p>Is there a better way to do this?  I guess what I am asking is:  </p>
  
  <p><strong>Why are my fragment views inside my ViewPager getting destroyed when the parent fragment of the ViewPager is hidden?</strong></p>
  
  <p><strong>Update:</strong> this also happens when the application is "minimized" and then "restored" (by pressing the home action key and then returning).</p>
  
  <p>Per request, here's my pager adapter class:</p>
  
  <pre><code>public class MyInfoSlidePagerAdapter extends FragmentStatePagerAdapter {
  
      private ArrayList&lt;MyInfo&gt; infos = new ArrayList&lt;MyInfo&gt;();
  
      public MyInfoSlidePagerAdapter (FragmentManager fm) {
          super(fm);
      }
  
      public MyInfoSlidePagerAdapter (FragmentManager fm, MyInfo[] newInfos) {
          super(fm);
          setInfos(newInfos);
      }
  
      @Override
      public int getItemPosition(Object object) {
          int position = infos.indexOf(((MyInfoDetailsFragment)object).getMyInfo());
          return position &gt; 0 ? position : POSITION_NONE;
      }
  
      @Override
      public CharSequence getPageTitle(int position) {
          return infos.get(position).getName();
      }
  
      @Override
      public Fragment getItem(int i) {
          return infos.size() &gt; 0 ? MyInfoDetailsFragment.getNewInstance(infos.get(i)) : null;
      }
  
      @Override
      public int getCount() {
          return infos.size();
      }
  
      public Location getMyInfoAtPosition(int i) {
          return infos.get(i);
      }
  
      public void setInfos(MyInfo[] newInfos) {
          infos = new ArrayList&lt;MyInfo&gt;(Arrays.asList(newInfos));
      }
  
      public int getPositionOfMyInfo(MyInfo info) {
          return infos.indexOf(info);
      }
  }
  </code></pre>
  
  <p>I've renamed some variables but other than that it is exactly what I have.</p>