title: How can I switch between two fragments, without recreating the fragments each time?
body: <p>I'm working on an android application, that uses a navigation drawer to switch between two fragments.  However, each time I switch, the fragment is completely recreated.</p>
  
  <p>Here is the code from my main activity.</p>
  
  <pre><code>/* The click listener for ListView in the navigation drawer */
  private class DrawerItemClickListener implements ListView.OnItemClickListener {
      @Override
      public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {
          selectItem(position);
      }
  }
  
  private void selectItem(int position) {
      android.support.v4.app.Fragment fragment;
      String tag;
      android.support.v4.app.FragmentManager; fragmentManager = getSupportFragmentManager();
  
      switch(position) {
          case 0:
              if(fragmentManager.findFragmentByTag("one") != null) {
                  fragment = fragmentManager.findFragmentByTag("one");
              } else {
                  fragment = new OneFragment();
              }
              tag = "one";
              break;
          case 1:
              if(fragmentManager.findFragmentByTag("two") != null) {
                  fragment = fragmentManager.findFragmentByTag("two");
              } else {
                  fragment = new TwoFragment();
              }
              tag = "two";
              break;
      }
  
      fragment.setRetainInstance(true);
      fragmentManager.beginTransaction().replace(R.id.container, fragment, tag).commit();
  
      // update selected item and title, then close the drawer
      mDrawerList.setItemChecked(position, true);
      setTitle(mNavTitles[position]);
      mDrawerLayout.closeDrawer(mDrawerList);
  }
  </code></pre>
  
  <p>I've set up some debug logging, and every time selectItem is called, one fragment is destroyed, while the other is created.</p>
  
  <p>Is there any way to prevent the fragments from being recreated, and just reuse them instead?</p>