This section learns the life cycle of fragment, I first look at the fragment life cycle flowchart provided by Google's website
Let's add the log to activity and Fragment01 and Fragment02 with the code from the previous section, and I don't need to post it on the code, we use log analysis.
A: Start Fragment01 in activity
You can see that this is the same as the process.
B: Then press the back key to return
You can see the display fragment paused first, activity paused, then fragment stopped, activity stopped, fragment destroyed, activity destroyed.
C: When you start Fragment01, press the home button
You can see the display fragment paused first, activity paused, then fragment stopped, activity stopped.
D: After the C case, then start the app again
You can see that the activity first restarts, then the fragment starts again, then the activity runs, and then the fragment runs
E: After starting Fragment01, start the Fragment02 again
You can see first Fragment01 completely destroyed, loaded Fragment02 again
Summarize:
1: You can see that fragment is part of the activity interface and will be fragment when activity is created
2:fragment's life cycle is affected by activity, and when activity stops, fragment also stops
3: After the activity is run (after the Onresume method call, before the OnPause method call), each fragment can be manipulated individually, such as add, delete
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Fragment life cycle of Android learning