Difference between add(), replace(), and addToBackStack()

后端 未结 9 1755
终归单人心
终归单人心 2020-11-22 05:40

What is the main difference between calling these methods:

fragmentTransaction.addToBackStack(name);
fragmentTransaction.replace(containerViewId, fragment, t         


        
9条回答
  •  生来不讨喜
    2020-11-22 06:25

    Important thing to be noticed:

    Difference between Replace and Replace with backstack is whenever we use only replace then the fragment is destroyed ( ondestroy() is called ) and when we use replace with backstack then fragments onDestroy() is not called ( i.e when back button is pressed fragment is invoked with its onCreateView())

提交回复
热议问题