The Fragment Lifecycle
A fragment is a component with its own lifecycle. Understanding the fragment lifecycle is critical as it provides callbacks at certain stages of fragment creation, running state, and destruction where you can configure the initialization, display, and cleanup. Fragments run in an activity, and the fragment's lifecycle is bound to the activity's lifecycle.
In many ways, the fragment lifecycle is very similar to the activity lifecycle, and at first glance, it appears that the former replicates the latter. There are as many callbacks that are the same or similar in the fragment lifecycle as there are in the activity lifecycle, such as onCreate(savedInstanceState: Bundle?)
.
The fragment lifecycle is tied to the activity lifecycle, so wherever fragments are used, the fragment callbacks are interleaved with the activity callbacks.
Note
The full sequence of the interaction between fragments and activities is illustrated in the official docs:...