Android-Fragment Lifecycle
Each fragment has a unique lifecycle, but because of its relationship to the Activity to which it belongs, the lifecycle of the fragment is influenced by the lifecycle of the activity.
onAttach(): An Activity is connected to the Fragment. To link the Fragment to its hosting Activity, this method is called.
onCreate(): It’s creating the Fragment. You can initialize important components and set up initial states at this point.
onCreateView(): This technique is used by the system to build the fragment’s user interface. This method returns the View component to draw the UI, which is the root of the fragment’s layout.
onViewCreated(): It shows that the activity where the fragment is present has been created. Before calling this method, the fragment’s view hierarchy was also initialized.
onStart(): This method is used by the system to display the fragment on the user’s device.
onResume(): The Fragment can be seen and is engaged in communication with the user. Here, you should initiate animations and refresh data, among other things.
onPause(): Although still visible in part, the fragment is stopped communicating with the user. Normally, you should store persistent states or stop movements here.
onStop(): A method used to remove the fragment from the user’s screen and end its operation.
onDestroyView(): The view hierarchy of the Fragment is being removed. To prevent memory leaks, clean up any free space or references.
onDestroy(): The view hierarchy of the Fragment is being removed. To prevent memory leaks, clean up any free space or references.
onDetach(): It is separating the Fragment from the Activity that is hosting it. Before the Fragment is totally gone, this is the last callback.