What’s the difference between detaching a Fragment and removing it?

The detach method removes the fragment from the UI, but its state is maintained by the Fragment Manager. This means you can reuse this fragment by calling the attach method, with a modified ViewHierarchy

Remove means the fragment instance cannot be re-attached. You will have to add it again to the fragment transaction.

Source Comment

You’ll notice that when a Fragment is detached, its onPause, onStop and onDestroyView methods are called only (in that order). On the other hand, when a Fragment is removed, its onPause, onStop, onDestroyView, onDestroy and onDetach methods are called (in that order). Similarly, when attaching, the Fragment’s onCreateView, onStart and onResume methods are called only; and when adding, the Fragment’s onAttach, onCreate, onCreateView, onStart and onResume methods are called (in that order). – Adil Hussain

Leave a Comment