Fragments

Fragments will likely become a staple of almost every real app you make. They are so useful; there are so many reasons to use them; and once you get used to them, they are so simple. There is almost no reason not to use them.

Fragments are reusable elements of an app just like any class, but as mentioned previously, they have special features, such as the ability to load their own view as well as having their very own lifecycle methods that make them perfect to achieve the goals that we've discussed in the Real-world apps section.

Let's dig a bit deeper into Fragments one feature at a time.

Fragments have a lifecycle too

We can set up and control Fragments very much like we do Activities, by overriding the appropriate lifecycle methods. ...

Get Android Programming for Beginners now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.