For the More Curious: Rotation Before Fragments

Fragments were introduced in Honeycomb and were only available for phones with Ice Cream Sandwich. Rotation problems, on the other hand, have been around since the beginning.

To appreciate the charm of retained fragments, it helps to have an idea of what life was like before they existed. It was like being poked in the eye with a sharp stick:

  • You want to retain an object across configuration changes? This requires a method called onRetainNonConfigurationInstance(). You override onRetainNonConfigurationInstance() to return the object you want to retain. When you want it back later, you call getLastNonConfigurationInstance(). Poke.

  • You want to retain more than one object in an activity? Too bad. ...

Get Android Programming: The Big Nerd Ranch Guide 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.