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, the running state, and destruction that configure the initialization, display, and cleanup. Fragments run in an activity, and a 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.
The same steps are gone through to initialize the fragment and prepare for it to be displayed to the user before being available...