Static vs. Dynamic Fragments

Sometimes, you will have a fragment that should be around as long as your activity is around. For that, you can use “static fragments”, where you use an element in a layout resource to specify where the fragment should go and how big it should be.

More often, though, your fragments will come and go, based on user input:

In all of these cases, in a fragment-based UI, you will use dynamic fragments.

Roughly speaking, there are two ways of employing dynamic fragments:

  1. Manually, using FragmentManager and FragmentTransaction classes, as we will explore in this chapter
  2. Using the Jetpack Navigation component, which we will see in the next chapter

Prev Table of Contents Next

This book is licensed under the Creative Commons Attribution-ShareAlike 4.0 International license.