
We can also implement a fragment without having any user interface (UI). In android, we can insert the fragment into activity layout by using element and by dividing the layout of activity into fragments, we can modify the appearance of an app design at runtime. In case if we pause an activity, all the fragments related to an activity will also be stopped.

Generally in android, the fragment must be included in an activity due to that the fragment lifecycle will always be affected by the host activity life cycle. In android, the fragment will act as a sub-activity and we can reuse it in multiple activities. We can add or remove fragments in an activity while the activity is running. The fragment has its own lifecycle call-backs and accepts its own input events. We can build multi-pane UI by combining multiple fragments in a single activity and we can reuse the same fragment in multiple activities.

By using fragments we can create flexible UI designs that can be adjusted based on the device screen size such as tablets, smartphones. In android, Fragments are the modular section of activity design and these are used to represent the behavior of user interface (UI) in an activity.
