Android fragment-Overview

Source: Internet
Author: User

A fragment represents a behavior or a part of the user interface in an activity. You can combine multiple fragment in an activity to create a multi-panel user interface, and you can reuse the same fragment in multiple activities. You can think of a frament as an activity module, which has its own lifecycle and accepts their own input events, and can be added or deleted when the activity is running (this is like a "sub-activity", which can be reused in different activities ).

Frament must be embedded in an activity, and the lifecycle of fragment is directly affected by this activity. For example, when an activity is terminated, all fragment in the activity will also be terminated. When the activity is destroyed, all fragment in the activity will also be destroyed. However, when an activity is running (that is, when the activity is restored), you can maintain each fragment independently, such as adding or deleting them. When you execute such a fragment transaction, you can also add it to the rollback stack managed by the activity. In the activity, the portal for each rollback stack is a record for a fragment transaction. By pressing the rollback button, the rollback stack allows the user to return a fragment transaction (navigation backward ).

 

When you add a fragment as part of the activity layout, it lives in the hierarchy tree of the internal activity's viewgroup, and fragment defines its own view layout. You can insert a fragment to your activity by declaring fragment in the activity layout file, orCodeAdd fragment to an existing viewgroup. However, fragment is not necessary as part of the activity layout. You can also use fragment without your own interface to make it an invisible worker of the activity.

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.