Fragment Summary: fragment lifecycle and comparison with activity Lifecycle

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.