title: How to handle orientation change using fragment?
body: <p>I now have 2 fragment, one fragment handle portrait mode then another handle landscape mode. But the problem is that when rotate from portrait to landscape then back to portrait. It will not show the same thing that show on the first portrait mode. Is there any code that can solve this problem?</p>
  
  <p>This code is inside the fragment holder:</p>
  
  <pre><code>@Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.frag_holder);
  
      FragmentManager fm = getSupportFragmentManager();
  
      final Fragment fragment = Frag.newInstance(); //Portrait layout
      final Fragment fragment2 = Frag2.newInstance(); //Landscape layout
  
      int orientation = getResources().getConfiguration().orientation; //check whether is it portrait or landscape
  
  
      if(orientation == Configuration.ORIENTATION_PORTRAIT){
          Fragment fragTAG = fm.findFragmentByTag(TAG_P);
          if(fragTAG == null){
              Log.i("test","test");
                  fm.beginTransaction()
                          .replace(R.id.fragPlaceHolder, fragment, TAG_P)
                          .commit(); //Portrait
          }
          else{
              fm.beginTransaction().replace(R.id.fragPlaceHolder,fragTAG).commit();
          }
  
      }
      if(orientation == Configuration.ORIENTATION_LANDSCAPE){
          Fragment fragTAG = fm.findFragmentByTag(TAG_L);
          if(fragTAG == null){
                  fm.beginTransaction()
                          .replace(R.id.fragPlaceHolder, fragment2, TAG_L)
                          .commit(); //Landscape
          }
          else{
              fm.beginTransaction().replace(R.id.fragPlaceHolder,fragTAG).commit();
          }
      }
  
  }
  </code></pre>
  
  <p>}</p>