Fragment Lifecycle Flashcards
onAttach
The first stage of Fragment initialization.
onCreate
The system calls this when creating the fragment. Within your implementation, you should initialize essential components of the fragment that you want to retain when the fragment is paused or stopped, then resumed.
onCreateView
The system calls this 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 from this method that is the root of your fragment’s layout. You can return null if the fragment does not provide a UI.
When the Activity that the Fragment has been included in returns from the Activity stack, the logic here is run as part of the resuming process.
onActivityCreated
The Activity the Fragment is in has been fully created or resumed.
onStart
Called when the Fragment has been started.
onResume
This will run when the Fragment resumes, and is the last point for logic changed before the Fragment is considered active.
onPause
As the Fragment is placed into the back stack, the logic here is processed.
onStop
The Fragment is going to be destroyed soon, so the logic can be run here.
onDestroyView
The current view is going to either load the Fragment back to the Activity cycle through onCreateView() or be destroyed.
onDestroy
The Fragment is going to be destroyed; this is the last chance for the logic to be run before the Fragment is destroyed and detached from the view.
onDetach
As the Fragment is removed, this is the last method you can work with as part of the Fragment-destroy process.