Simple Persistence with SharedPreferences

In your app, there will only be one active query at a time. PhotoGalleryViewModel persists the query for the user’s perceived life of the fragment. But the query should also be persisted between restarts of the app (even if the user turns off the device).

You will achieve this using shared preferences. Any time the user submits a query, you will write the search term to shared preferences, overwriting whatever query was there before. When the application first launches, you will pull the stored query from shared preferences and use it to execute a Flickr search.

Shared preferences are files on the filesystem that you read and edit using the SharedPreferences class. An instance of SharedPreferences ...

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