Can someone explain why this code isn't working?
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();
}
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.
I'm simply trying to load an existing version of a fragment by calling it by its tag.
In my mind the above code would execute as follows:
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 }
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 }
Edit
Slightly updated code. Same problem, new fragments are made instead of existing instances of the fragments getting loaded.
Clarification
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.