Fragment is a new concept in Android honeycomb 3.0. The fragment name is fragment, but it is very similar to activity. Fragment is used to describe some behaviors or some user interfaces. In an activity, you can combine multiple fragment to create multiple UI panels in a single activity, and reuse fragment in multiple activities. you can think of fragment as a module in an activity. fragment has its own lifecycle, receives its own input events, and you can add or remove it from the running activity.
A fragment must always be embedded in an activity, and the lifecycle of the fragment is affected by the activity. For example, when the activity is paused, all fragments in the activity will be released by destroy. However, when an activity is running, such as resume, you can independently manipulate each fragment, such as adding or deleting an activity.
Fragment has its own lifecycle like activity, for example:
When creating a fragment, you must first define the activity to which it is attached, and then inherit the fragment through a subclass. In addition, you can add the corresponding <fragment> </fragment> In the activity layout file.