I have a bug where a fragment just refuses to be removed. I have been through a dozen other posts here with near identical titles, but none of the solutions apply to my problem.
The fragment is added like this:
CustomFragment fragment = new CustomFragment();
fragmentManager.beginTransaction().replace(R.id.fragment_container, fragment, "fragment_tag").commit();
It is not added to backstack.
Then it is removed like this:
Fragment fragmentToRemove = fragmentManager.findFragmentByTag("fragment_tag");
if (fragmentToRemove != null) {
fragmentManager.beginTransaction().remove(fragmentToRemove).commit();
}
To make sure I check:
fragmentManager.getFragments() -> empty
fragmentManager.getBackStackEntryCount() -> 0
Seems fine and dandy, right? But when I then call:
fragmentManager.findFragmentByTag("fragment_tag");
I still find the same fragment, with the same id, that I just removed. What gives? I have lost track of all the things I have tried, suffice to say that obvious things like popBackStackImmediate() and commitNow() did not work. Hoping someone else has run into this one before and can tell me what I am missing.