Remove fragment doesn't work after addToBackStack

When I start a fragment and add to BackStack it cannot be removed with FragmentTransaction.remove (), add like this:

 
mManager.beginTransaction()
        .add(R.id.fragment_container, new FB(), "B")
        .addToBackStack("addB")
        .commit();

      

there is code here:  

 FB fb = (FB) mManager.findFragmentByTag("B");
        if (fb != null) {
            FragmentTransaction ft = mManager.beginTransaction();
            ft.remove(fb);
            ft.detach(fb);
            ft.addToBackStack("removeB");
            ft.commit();
        } else {
            showToast("B is not exist");
        }

      

after the first time I delete chunk B, I can still get chunk B

FB fb = (FB) mManager.findFragmentByTag("B")

and onDestory()

onPause()

onDetach()

don't work either.

How do I know if chunk B is being deleted?

Follow these steps to throw an exception:

java.lang.IllegalStateException: Fragment already added: FB{424365e0 #0 id=0x7f0c004f B}

actions:

addB -> removeB -> removeB -> onBackPressed();

      

+3


source to share





All Articles