title: Fragment on Screen Rotation
body: <p>I have added a viewpager to an activity which contains two page.</p>
  
  <p>In onCreate of activity I add fragments to a fragmentAdapter:</p>
  
  <pre><code>public void onCreate(Bundle savedInstanceState)
  {
      ......
  
      FragmentAdapter fragmentAdapter = new FragmentAdapter
      (
          getSupportFragmentManager(),
          new Fragment[]{FragmentGame.builder(id), FragmentComments.builder(id)},
          new String[]{getString(R.string.gameInfo), getString(R.string.comments)}
      );
  
      ViewPager viewPager = (ViewPager) findViewById(R.id.viewPager);
      viewPager.setAdapter(fragmentAdapter);
  
  public static FragmentGame builder(long id)
  {
      FragmentGame fragmentGame = new FragmentGame();
  
      // fragmentGame.id = id;
  
      Bundle bundle = new Bundle();
      bundle.putLong(Constants.EXTRA_ID, id);
      fragmentGame.setArguments(bundle);
  
      return fragmentGame;
  }
  </code></pre>
  
  <p>First time that activity is created the <strong>onCreateView</strong> of fragment is called as it's expected. </p>
  
  <p>The strange behaviour is when the screen is rotated for the first time the <strong>onCreateView</strong> of fragment is called twice but the second call only has the correct <strong>id</strong> and for the first call <strong>id</strong> is 0. </p>
  
  <p>On second screen rotation, <strong>onCreateView</strong> is called three times and again only the last one has id.</p>
  
  <p>By more screen rotation, <strong>onCreateView</strong> calls increase.</p>
  
  <p>I found some related question about fragment and screen rotation but I can't figure out why this happens and how to do it the right way.</p>
  
  <p>----- UPDATE ------</p>
  
  <p>The ID problem is solved as I replaced bundle with direct value setting.</p>