title: ViewPager fragments disappear when change screen rotation
body: <p>I'm working on android application that contains <code>ViewPager</code> with <code>Fragment</code>s, like this:</p>
  
  <p><code>MainActivity</code>(<code>MainActivityFragment</code>(<code>screenSlideViewPager</code>(<code>Fragment</code>s))), which means:</p>
  
  <p><code>Activity</code> <strong>contains</strong> <code>Fragment</code> <strong>contains</strong> <code>ViewPager</code> <strong>contains</strong> <code>Fragment</code>s</p>
  
  <p>Now my problem is when rotate device or change screen rotation all Fragments in ViewPager are disappear.</p>
  
  <p>any ideas to solve this issue?</p>
  
  <p><strong>EDIT 1</strong></p>
  
  <p>MainActivity.java:</p>
  
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
      if (getSupportFragmentManager().findFragmentByTag(TAG) == null) {
          final FragmentTransaction ft = getSupportFragmentManager()
                  .beginTransaction();
          ft.add(android.R.id.content, new MainActivityFragment(), TAG);
          ft.commit();
      }
  }
  </code></pre>
  
  <p>MainActivityFragment.java:</p>
  
  <pre><code>public class MainActivityFragment extends Fragment {
      private ViewPager mPager = null;
      private PagerAdapter mPageAdapter = null;
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
          final View reVal = inflater.inflate(R.layout.activity_main, container, false);
          mPager = (ViewPager) reVal.findViewById(R.id.pagerMainContent);
          mPageAdapter = new ScreenSlidePagerAdapter(getActivity().getFragmentManager());
          mPager.setAdapter(mPageAdapter);
          return reVal;
      }
  
      private MainGridViewFragment mainGridFragment;
      private AlphabetGridViewFragment alphabetGridFragment;
  
      private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter {
          public ScreenSlidePagerAdapter(FragmentManager fm) {
              super(fm);
          }
  
          @Override
          public android.app.Fragment getItem(int position) {
              switch (position) {
                  case 1:
                      mainGridFragment = new MainGridViewFragment();
                      return mainGridFragment;
                  case 0:
                      alphabetGridFragment = new AlphabetGridViewFragment();
                      return alphabetGridFragment;
                  default:
                      return null;
              }
          }
  
          @Override
          public int getCount() {
              return 2;
          }
      }
  }
  </code></pre>
  
  <p><strong>EDIT 2</strong>
  <img src="https://i.stack.imgur.com/MCWOg.png" alt="The Activity After Screen Rotation"></p>
  
  <p>Obviously <code>MainActivity</code> and <code>MainActivityFragment</code> are loaded, and the proof is The <code>ActionBar</code>, 
  notice also that <code>ViewPager</code> is loaded too, because you still can navigate between pages (the blue light means that the pager reached to last page) but you can't see its content.</p>