title: Handle Activity with Fragments with different layout for portrait and landscape
body: <p>I have an <code>Activity</code> with <code>Fragment</code> in it, and it has different layout xml files for landscape and portrait mode.</p>
  
  <p>I try to use <code>onConfigurationChanged()</code> like this:</p>
  
  <pre><code>public void onConfigurationChanged(Configuration newConfig) {
      super.onConfigurationChanged(newConfig);
      setContentView(R.layout.hdmain);
  }
  </code></pre>
  
  <p>Where <code>hdmain.xml</code> is put in <code>layout-land</code> and <code>layout-port</code> folder. Then I meet the Fragment lifecycle problem:</p>
  
  <pre><code>java.lang.IllegalArgumentException: Binary XML file line #9: Duplicate id 0x7f0c0019, tag null, or parent id 0xffffffff with another fragment for org.sais.hdmeridian.HDMainActivity$TabFragment
  </code></pre>
  
  <p>It looks like the Fragment is still there, and since I changed the layout of Activity, a new Fragment is created then duplicated.</p>
  
  <p>What's a smart way to avoid this? Or does Android has some better solution to handle this problem?</p>