Rotation and Retained Fragments
Let’s take a closer look at how retained fragments work. Retained fragments take advantage of the fact that a fragment’s view can be destroyed and recreated without having to destroy the fragment itself.
During a configuration change, the FragmentManager first destroys the views of the fragments in its list. Fragment views always get destroyed and recreated on a configuration change for the same reasons that activity views are destroyed and recreated: If you have a new configuration, then you might need new resources. Just in case better matching resources are now available, you rebuild the view from scratch.
Next, the FragmentManager checks the retainInstance property of each fragment. If it is false, which ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access