- onAttach
Called when a fragment is first attached to its activity - onCreate
Called to do initial creation of a fragment
Note that this can be called while the fragment’s activity is still in the process of being created. As such, you can not rely on
Things like the activity’s content view hierarchy being initialized - onCreateView
Called to have the fragment instantiate its user interface view
If you return a View from here, you will later be called in onDestroyView when the view is being released. - onViewCreated
Called immediately after onCreateView has returned, but before any saved state has been restored in to the view. This gives subclasses a chance to initialize themselves once they know their view hierarchy has been completely created. The fragment’s view hierarchy is not however attached to its parent at this point. - onActivityCreated
Called when the fragment’s activity has been created and this
fragment’s view hierarchy instantiated
It can be used to do final initialization once these pieces are in place, such as retrieving views or restoring state.It is also useful for fragments that use setRetainInstance(boolean) to retain their instance,
as this callback tells the fragment when it is fully associated with the new activity instance. - onStart
Called when the Fragment is visible to the user.
This is generallytied toActivity.onStart of the containing Activity’s lifecycle. - onResume
Called when the fragment is visible to the user and actively running.
This is generally tied to Activity.onResume of the containing Activity’s lifecycle. - onPause
Called when the Fragment is no longer resumed.
This is generally tied to Activity.onPause of the containing Activity’s lifecycle. - onStop
Called when the Fragment is no longer started.
This is generally tied to Activity.onStop of the containing Activity’s lifecycle. - onDestroyView
Called when the view previously created by onCreateView has been detached from the fragment. The next time the fragment needs to be displayed, a new view will be created. - onDestroyView
Called when the fragment is no longer in use. - onDetach
Called when the fragment is no longer attached to its activity
Fragment生命周期
最新推荐文章于 2022-07-21 19:54:03 发布