# 4. Fragments

Imagine Chrome redrew all your tabs and bookmarks each time you changed the current page, or imagine if you dumped out and put back everything in your pencil case each time you needed an eraser. There are clearly some actions in those two scenarios that do not need changing, so why go through the hassle of taking away something before putting it all back?&#x20;

That’s often the case in many apps: there are parts of a UI that doesn't need any change from screen to screen. Android’s solution to this problem is fittingly called a Fragment, which allows developers to change sections of the app without changing the activity.

In this chapter, we will be going into details about the difference between a `Fragment` and an `Activity`, and the basic implementation of a `Fragment`.&#x20;

## Topics

* What are Fragments?
* Lifecycle of a Fragment
* Integrating a Fragment into an Activity
* Sharing Data Between Fragments
* ViewPagers


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://android-course.cornellappdev.com/archive/archived-native-android-textbook-pages/5.-fragments.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
