Networking Across Configuration Changes

Now that you have your app deserializing JSON into model objects, take a closer look at how your implementation behaves when a configuration change occurs. Run your app, make sure auto-rotate is turned on for your device or emulator, and then rotate the device quickly five or so times in a row. Inspect the Logcat output, filtering by PhotoGalleryFragment and turning soft wraps off (Figure 24.8).

Figure 24.8  Logcat output across multiple rotations

Logcat output across multiple rotations

What is going on here? A new network request is made every time you rotate the device. This is because you kick off the request in onCreate(…) ...

Get Android Programming: The Big Nerd Ranch Guide, 4th Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.