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 O’Reilly online learning.

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