October 2019
Intermediate to advanced
624 pages
20h 7m
English
By default, the retainInstance property of a fragment is false.
This means it is not retained but is destroyed and re-created on rotation along with the activity that hosts it.
Calling setRetainInstance(true) retains the fragment.
When a fragment is retained, the fragment is not destroyed with the activity.
Instead, it is preserved and passed along intact to the new activity.
When you retain a fragment, you can count on all of its instance variables to keep the same values. When you reach for them, they are simply there.
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 re-created ...
Read now
Unlock full access