popBackStack() after addToBackStack does not work

后端 未结 6 1690
野趣味
野趣味 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:51

    You should call

    fragmentTransaction.addToBackStack(null);
    

    after performing all operations such as add(), remove(), and replace() and Just before commit(). Only then this transaction will be added to backstack. Only then you will be able to return to previous fragment state with Back button. Details here.

提交回复
热议问题