Android didn't always support Fragments. The early versions of Android were designed for phones when screens had relatively small displays. It wasn't until Android started being used on tablets that there was a need to split the screen into smaller sections. Android 3.0 introduced the Fragments class and the Fragment Manager.
Along with a new class, also came the Fragment Lifecycle. The Fragment Lifecycle is similar to the Activity Lifecycle introduced in Chapter 1, Activities, as most events parallel the Activity Lifecycle.
Here's a brief overview of the main callbacks:
- onAttach(): It's called when the Fragment is associated with an Activity.
- onCreate(): It's called when the Fragment is first created.
- onCreateView(): It's called when the Fragment is about to be displayed for the first time.
- onActivityCreated(): It&apos...