For the More Curious: More on Rotation Handling

The onSaveInstanceState(Bundle) is another tool you have used to handle rotation. In fact, if your app does not have any problems with rotation, it is because the default behavior of onSaveInstanceState(…) is working.

Your CriminalIntent app is a good example. CrimeFragment is not retained, but if you make changes to the crime’s title or toggle the checkbox, the new states of these View objects are automatically saved out and restored after rotation. This is what onSaveInstanceState(…) was designed to do – save out and restore the UI state of your app.

The major difference between overriding Fragment.onSaveInstanceState(…) and retaining the fragment is how long the preserved data ...

Get Android Programming: The Big Nerd Ranch Guide, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.