popBackStack() after addToBackStack does not work

后端 未结 6 1257
梦毁少年i
梦毁少年i 2021-02-11 20:43

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:58

    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.

提交回复
热议问题