I just went through the documentation of the attach()
and detach()
methods of FragmentTransaction
:
attach()
: Re-attach a fragment after it had previously been detached from the UI withdetach(Fragment)
. This causes its view hierarchy to be re-created, attached to the UI, and displayed.
Well, what does that mean?
More specifically, I saw an example:
mMapFragment = new MapFragment(); ft.beginTransaction(mMapFragment) .attach() .add(R.id.container, mMapFragment) .commit();
I deleted the
attach()
and tried again: I did not notice any difference. What does theattach
do in this example? What is the difference compared to this:ft.beginTransaction() .add(R.id.container, mMapFragment) .commit();
In case the example above is not good enough to show the difference... I just want to know when do we need to call the
attach()
anddetach()
explicitly? It would be better if you can explain the difference with respect to add/remove/replace.