In FragmentTransaction item on Android docs, it is described that the method replace()
is the same as calling the method remove()
for all fragments added in the currently view and then called the method add()
. In this case, to recover the previous fragment, we could use addBackToStack()
, it means that transaction state is still being managed by the fragment manager and will reverse its operation when we popped off the stack.
In the other hand, when we implement the transaction using add()
, beyond the use of add().addBackToStack()
, we can use the detach()
method and recovering the fragment using attach()
, which have the same behavior that addBackToStack()
.
So what is the difference behind the scenes between these scenarios?