title: How to copy the fragment stack after an orientation change?
body: <p>I want to create an app for smartphone and tablet support. Reading the <a href="https://developer.android.com/guide/practices/tablets-and-handsets.html#Fragments" rel="nofollow noreferrer">android documentation</a>, I noticed that the best way to implement this is to use fragments and multiple layouts.</p>
  
  <p>I have two layouts for my application:</p>
  
  <p><a href="https://i.stack.imgur.com/KCRho.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KCRho.png" alt="Tablet Landscape Layout"></a></p>
  
  <p>In this layout, you can select an item from the red pane and a new selection is presented on the green one. Now the important part: You can select an item of the green pane and it adds a new fragment to the green pane. I also added them to the BackStack. This works fine with the following code.</p>
  
  <pre><code>@Override
  public void OnItemSelected(String id) {
      int resourceTargetID = mTwoPane? R.id.green_pane : R.id.blue_pane;
  
      Bundle arguments = new Bundle();
      arguments.putString(RedPaneFragment.ARG_ITEM_ID, id);
      RedPaneFragment fragment = new RedPaneFragment();
      fragment.setArguments(arguments);
  
      FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
      fragmentTransaction.replace(resourceTargetID, fragment, REDPANE_FRAGMENT_TAG);
      fragmentTransaction.addToBackStack(null);
      fragmentTransaction.commit();
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/Tmayp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Tmayp.png" alt="Smartphone / Tablet Portait Layout"></a></p>
  
  <p>This is the smartphone (or tablet portrait) layout and it works with the mentioned code aswell. The only difference is that the green- and blue framed panes are stacked up into the blue pane.</p>
  
  <p><strong>My Problem:</strong>
  The user is browsing through the lists and has a stack with 1 green pane and multiple green panes (i.e. a stack of 5 fragments). Now the user changes the orientation and the layout swaps to the portrait design. But it forgets the whole stack and is starting with the green pane again without the red ones above.</p>
  
  <p>I do not know how to implement this, but I am sure there is a way to do this.</p>