Where You Get Your Fragments From

We use a Fragment class as the basis for our fragments. There are multiple Fragment class implementations, though, which makes things confusing.

The Jetpack edition of fragments is in the androidx namespace, specifically androidx.fragment.app.Fragment. That is the Fragment class that we will be using in this book.

The Jetpack Fragment class is based on the one from the Android Support Library. If you see references to android.support.v4.app.Fragment, that is the Android Support Library edition. This is very obsolete and should not be used.

You will also find android.app.Fragment. This is the framework implementation of fragments. It has been officially deprecated, with Google steering developers towards a library-based implementation. The problem is that fragments have had quite a few bugs over the years. Framework classes are only updated when the OS is updated, and for many users that means the framework classes are rarely updated and are usually out of date. By contrast, you as the app developer control which version of the libraries that you use, so you can ensure that you are using up-to-date versions that contains relevant bug fixes.

Fortunately, Java and Kotlin are strongly-typed languages, so it will be difficult for you to accidentally use the wrong Fragment… though “difficult” is not “impossible”.


Prev Table of Contents Next

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