What is fragment and its lifecycle Flashcards
How is it related to activity
A fragment life cycle is closely related to the lifecycle of its host activity which means when the activity is in the pause state, all the fragments available in the activity will also stop.
onAttatch
This method called first, To know that our fragment has been attached to an activity. We are passing the Activity that will host our fragment.
onCreate
This method called when a fragment instance initializes, just after the onAttach where fragment attaches to the host activity.
onCreateView()
The method called when it’s time for the fragment to draw its user interface for the first time. To draw a UI for your fragment, you must return a View component from this method that is the root of your fragment’s layout. You can return null if the fragment does not provide a UI.
onActivityCreated
This method called when Activity completes its onCreate() method
onStart()
This method called when a fragment is visible.
onResume()
This method called when a fragment is visible and allowing the user to interact with it. Fragment resumes only after activity resumes.
onPause
onPause() — This method called when a fragment is not allowing the user to interact; the fragment will get change with other fragment or it gets removed from activity or fragment’s activity called a pause.
onStop
This method called when the fragment is no longer visible; the fragment will get change with other fragment or it gets removed from activity or fragment’s activity called stop.
onDestroyView
This method called when the view and related resources created in onCreateView() are removed from the activity’s view hierarchy and destroyed.
onDestroy
This method called when the fragment does its final clean up.
onDetach
This method called when the fragment is detached from its host activity.