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

What is the main difference between calling these methods:

fragmentTransaction.addToBackStack(name);
fragmentTransaction.replace(containerViewId, fragment, tag);
fragmentTransaction.add(containerViewId, fragment, tag);

What does it mean to replace an already existing fragment, and adding a fragment to the activity state, and adding an activity to the back stack?

Secondly, with findFragmentByTag(), does this search for tag added by the add()/replace() method or the addToBackStack() method?

9 Answers
9

Leave a Comment