Storing persistent activity data
Being able to store information about our activities on a temporary basis is very useful, but more often than not, we will want our application to remember information across multiple sessions.
Android supports SQLite, but that could be a lot of overhead for simple data, such as the user's name or a high score. Fortunately, Android also provides a lightweight option for these scenarios, with SharedPreferences
.
Getting ready
You can either use the project from the previous recipe or start a new project and call it PersistentData
(in a real-world application, you'll likely be doing both anyway). In the previous recipe, we saved mCounter
in the session state. In this recipe, we'll add a new method to handle onPause() ...
Get Android Application Development Cookbook - 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.