life cycle, and what does it do in the life cycle ?
Onattach: When the method is called,Fragment is connected to its parent activity, and a reference to the parent activity is obtained .
OnCreate: Call this method to initialize the fragment ; initialize fragment
Oncreateview: Once Fragment has been created, call this method when creating its own user interface, create, or populate Fragment UI , and return it if this Fragment No UI, then NULL is returned
onactivitycreated: This method is called once the UI of the parent Activity and Fragment has been created, and the initialization of the Fragment is completed - especially when the parent Activity is initialized or the Fragment View is fully populated.
OnStart: Called at the beginning of the visible life cycle; apply all required UI changes, now Fragment is visible
Onresume: Called at the beginning of the active life cycle; resuming all paused Fragment requires UI Update, thread, or process, but inactive it is paused
OnPause: Called at the end of the activity life cycle , when activity is not active foreground activity , you need to pause UI updates, suspend threads, or pause those that do not need to be updated centralized processing of the CPU. Since this method is called, the process may be terminated, so all editing and state change information is saved.
Onsaveinstancestate: Called at the end of the active life cycle, calling the method to save the state change of the UI, and saving the state change information for the UI to Saveinstancestate , this bundle is passed to onCreate,Oncreateview, and onactivitycreate(if its parent Activity is terminated and restarted) in the method.
OnStop: Call this method at the end of the visible life cycle , pausing the rest of the UI update, suspending the thread, or pausing the processing that is not needed when the Fragment is not visible .
Ondestroyview: This method is called when the view of Fragment is detached, and the associated view is cleared
OnDestroy: Called at the end of the entire life cycle, eliminating all resources, including ending the thread and shutting down the database connection.
Ondetach: When Fragmet is detached from its parent Activity , the method is called
Scenario Demo : switch to the Fragment
Onattach
OnCreate
Oncreateview
onactivitycreated
OnStart
Onresume
Screen off:
OnPause
Onsaveinstancestate
OnStop
Screen unlock
OnStart
Onresume
Switch to another Fragment:
OnPause
OnStop
Ondestroyview
switch back to its own Fragment:
Oncreateview
onactivitycreated
OnStart
Onresume
Back to Desktop
OnPause
Onsaveinstancestate
OnStop
Back to Application
OnStart
Onresume
Exit the App
OnPause
OnStop
Ondestroyview
OnDestroy
Ondetach
What does android-fragment do in the life cycle?