Hosting a Fragment

When fragments were first introduced, developers had to jump through numerous hoops to display them. In 2019, Google introduced the FragmentContainerView, which makes it easier to create host containers for a fragment. In this section, you will use a FragmentContainerView to host your CrimeDetailFragment. Then you will learn about the FragmentManager and the fragment lifecycle. Finally, you will tie up one loose end in CrimeDetailFragment.

Defining a FragmentContainerView

FragmentContainerView is, as its name suggests, built to contain fragments. Fragments have changed significantly over the years, so FragmentContainerView helps provide a consistent environment for fragments to operate in. Much like the views ...

Get Android Programming: The Big Nerd Ranch Guide, 5th Edition 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.