Simple Persistence with DataStore
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 the DataStore AndroidX library. DataStore is a library that helps you interact with shared preferences, files stored on the filesystem that your app can use to store key-value pairs. 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 ...
Get Android Programming: The Big Nerd Ranch Guide, 5th 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.