title: Displaying Fragments with data in a ViewPager on screen rotation
body: <p>So in my MainActivity OnCreate I create 3 Fragments, each filled with different data. I then  add these Fragments to my ViewPagerAdapter.</p>
  
  <pre><code>    ViewPagerAdapter viewPagerAdapter = new ViewPagerAdapter(getSupportFragmentManager());
      MealsFragment exploreFragment = null;
      MealsFragment favoriteFragment = null;
      MealsFragment localFragment = null;
  
      //if there is no saved instance, create fragments with passed data as args and add them to the viewpageradapter
      if(savedInstanceState == null){
          exploreFragment = fetchExploreMealsDataAndCreateFragment();
          favoriteFragment = fetchFavoriteMealsDataAndCreateFragment();
          localFragment = fetchLocalMealsDataAndCreateFragment();
      }
  
      //add fragments to the adapter
      viewPagerAdapter.addFragment(exploreFragment, "EXPLORE");
      viewPagerAdapter.addFragment(favoriteFragment, "FAVORITES");
      viewPagerAdapter.addFragment(localFragment, "LOCAL");
  
      //set adapter to the viewpager and link it with the different tabs
      mviewPager.setAdapter(viewPagerAdapter);
      mtabLayout.setupWithViewPager(mviewPager);
  </code></pre>
  
  <p>The 3 different fetch methods get the data from an API or DB, so I don't want to call these methods every time I rotate my screen and go through my lifecycle. That's why I firstly check if the savedInstanceState is null. But what happens now is that if my savedInstanceState is not null, the Fragments will be null since i initialised them that way. </p>
  
  <p>Apparently this is not a problem since when I rotate the screen, the fragments remain the same. I was wondering what is going on here behind the scenes as I don't think this is the correct way of handling my situation. Any suggestions of improvement are appreciated aswell.</p>
  
  <p>Thanks in advance!</p>
  
  <p>EDIT:</p>
  
  <p>Forgot to mention that ViewPagerAdapter is my own implementation of FragmentPageAdapter</p>
  
  <pre><code>public class ViewPagerAdapter extends FragmentPagerAdapter {
  private final List&lt;Fragment&gt; fragmentList = new ArrayList&lt;&gt;();
  private final List&lt;String&gt; fragmentTitleList = new ArrayList&lt;&gt;();
  
  public ViewPagerAdapter(FragmentManager fm) {
      super(fm);
  }
  
  @Override
  public Fragment getItem(int i) {
      return fragmentList.get(i);
  }
  
  @Override
  public int getCount() {
      return fragmentList.size();
  }
  
  @Nullable
  @Override
  public CharSequence getPageTitle(int position) {
      return fragmentTitleList.get(position);
  }
  
  public void addFragment(Fragment fragment, String title){
      fragmentList.add(fragment);
      fragmentTitleList.add(title);
  }
  </code></pre>
  
  <p>}</p>