1. Fragment lifecycle:
Let's take a look at the illustration in the Google help document:
// Attach the fragment to the current activity.
Public void onattach (activity ){
// Todo auto-generated method stub
Super. onattach (activity );
}
Public void oncreate (bundle savedinstancestate ){
// Todo auto-generated method stub
Super. oncreate (savedinstancestate );
}
// Convert the layout file to a view object through the Inflater object
Public View oncreateview (layoutinflater Inflater, viewgroup container,
Bundle savedinstancestate ){
// Todo auto-generated method stub
Return super. oncreateview (Inflater, container, savedinstancestate );
}
Public void onactivitycreated (bundle savedinstancestate ){
// Todo auto-generated method stub
Super. onactivitycreated (savedinstancestate );
}
2. Compare the activity lifecycle by printing logs:
I:
1. The first four methods called during fragmeng creation correspond to the oncreate () method in the activity.
If fragment is not displayed on the front-end when a call is received:
When you return to the fragment page:
When you exit the fragment page:
Fragment Summary: fragment lifecycle and comparison with activity Lifecycle