title: Android replace fragment with existing version
body: <p>Can someone explain why this code isn't working?</p>
  
  <pre><code>    Fragment f = fragmentManager.findFragmentByTag(tag);
  
      if (f == null) {
          fragmentManager.beginTransaction().replace(R.id.protokoll_content, fragment, tag).commit();
      } else {
          fragmentManager.beginTransaction().replace(R.id.protokoll_content, f).commit();
      }
  </code></pre>
  
  <p>I don't think you need much more to get what I'm trying to do, and I don't think the rest of the code is relevant to the problem. I'm like 99% certain this is the trouble zone.</p>
  
  <p>I'm simply trying to load an existing version of a fragment by calling it by its tag.</p>
  
  <p>In my mind the above code would execute as follows:</p>
  
  <p>IF (the fragment has no existing instance) { create a new one with a unique tag and replace the existing fragments in the container with it } </p>
  
  <p>OTHERWISE (the fragment DOES have an existing instance) { load that existing version instead of creating a new one and replace the current fragment with the found existing fragment }</p>
  
  <p><strong>Edit</strong></p>
  
  <p>Slightly updated code. Same problem, new fragments are made instead of existing instances of the fragments getting loaded.</p>
  
  <p><strong>Clarification</strong></p>
  
  <p>New fragments are made each time instead of existing ones getting loaded. If I write something, go to a new fragment and then try to go back the the old fragment all the text is wiped because new fragments get made instead of old ones getting loaded.</p>