Fragment life cycle of Android learning

Source: Internet
Author: User

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

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.