popBackStack() after addToBackStack does not work

后端 未结 6 1688
野趣味
野趣味 2021-02-11 20:29

My project contains two fragment :

  • FragmentA : the fragment loaded by default when the app starts
  • FragmentB : replace the fragmentA when a c
6条回答
  •  无人及你
    2021-02-11 20:49

    You use the getSupportedFragmentManager() to replace FragmentA by FragmentB. But you call popBackStack() on the getFragmentManager().

    If you are adding the Fragments to the android.support.v4.app.FragmentManager you also have to call popBackStack() on the same FragmentManager.

    This code should solve the problem:

    if (getSupportFragmentManager().getBackStackEntryCount() > 0){
        boolean done = getSupportFragmentManager().popBackStackImmediate();
    }
    

提交回复
热议问题