title: Best way to switch between two fragments
body: <p>I'm interested in the best way to have a single activity that switches between two fragments.  </p>
  
  <p>I've read probably 15 Stack Overflow posts and 5 blogs posts on how to do this, and, while I think I cobbled together a solution, I'm not convinced it's the best one.  So, I want to hear people's opinions on the right way to handle this, especially with regards to the lifecycle of the parent activity and the fragments.  </p>
  
  <p>Here is the situation in detail:</p>
  
  <ol>
  <li>A parent activity that can display one of two possible fragments. </li>
  <li>The two fragments have state that I would like to persist across a session, but does not necessarily need to be persisted between sessions.  </li>
  <li>A number of other activities, such that the parent activity and the fragments could get buried in the back stack and destroyed due to low memory.  </li>
  <li>I want the ability to use the back button to move between the fragments (So as I understand it, I can't use setRetainInstance).  </li>
  </ol>
  
  <p>In addition to general architecture advice, I have the following outstanding questions:</p>
  
  <ol>
  <li>If the parent activity is destroyed due to low memory, how do I guarantee that the states of both fragments will be retained, as per this post: <a href="https://stackoverflow.com/questions/8482606/when-a-fragment-is-replaced-and-put-in-the-back-stack-or-removed-does-it-stay">When a Fragment is replaced and put in the back stack (or removed) does it stay in memory?</a>.  Do I just need a pointer to each fragment in the parent activity?</li>
  <li>What is the best way for the parent activity to keep track of which fragment it is currently displaying?</li>
  </ol>
  
  <p>Thanks in advance!</p>