title: How to pop back stack for Activity with multiple Fragments?
body: <p><img src="https://i.stack.imgur.com/koUtq.jpg" alt="Activity layout picture"></p>
  
  <p>Assume I have an Activity which contains two FrameLayouts (let's call them FrameA and FrameB) which in turn <em>each</em> contain a Fragment (let's call them FragmentA1 and FragmentB1 respectively). Now, I commit a series of individual fragment transactions using code similar to the following...</p>
  
  <pre><code>getFragmentManager()
   .beginTransaction()
   .replace(frameId, fragment)
   .addToBackStack(null)
   .commit();
  </code></pre>
  
  <p>... such that I replace FragmentA1 in FrameA with FragmentA2, then I replace FragmentB1 in FrameB with FragmentB2, then I replace FragmentA2 in FrameA with FragmentA3, then I replace FragmentB2 in Frame2 with FragmentB3, and the final state looks like the picture above (where only FragmentA3 and FragmentB3 are visible).</p>
  
  <p>If I understood correctly how the back stack works, pressing 'back' will interleave popping of the Fragments between FrameA and FrameB (reflecting how I added them).</p>
  
  <p>Does anyone know if it is possible to pop the last transaction on FrameA or FrameB selectively? (i.e. if I pressed 'Pop FrameA' then FrameA would be transitioned back from FragmentA3 to FragmentA2 and, instead, if I pressed 'Pop FrameB' then FrameB would be transitioned back from FragmentB3 to FragmentB2)</p>
  
  <blockquote>
    <p><strong>Supplement:</strong> I know I can get the Fragment last added to a given FrameLayout using the <code>FragmentManager.findFragmentById(int framelayoutId)</code> method, but calling <code>FragmentTransaction.remove(fragment).commit()</code> only removes the Fragment from the View and does not transition the View back to the Fragment it previously displayed.</p>
  </blockquote>