Handling configuration changes with fragments

In Chapter 6, Making Your App Orientation-aware, we discussed how Android activities respond to device configuration changes. In this section, we will take a look at the fragment behavior in the event of configuration changes.

Like activities, fragment provides the OnSaveInstanceState() method that can be used to save the state of your fragment. This works in pretty much the same way as its activity counterpart. The OnSaveInstanceState() method supplies a Bundle instance into which we can dump the data bundles. The saved fragment instance can be retrieved from the OnCreate(), OnActivityCreated(), or OnCreateView() callback.

The following steps will guide you through saving and retaining the POI list ...

Get Xamarin Mobile Application Development for Android - Second 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.