4.3.5. SharedPreferences
You can have one or more files containing key–value pairs associated with each app—each key enables you to quickly look up a corresponding value. We use this capability to manipulate a file called searches in which we store the pairs of tags (the keys) and Twitter search queries (the values) that the user creates. To read the key–value pairs from this file we’ll use SharedPreferences objects (package android.content). To modify the file’s contents, we’ll use SharedPreferences.Editor objects (package android.content). The keys in the file must be Strings, and the values can be Strings or primitive-type values.
This app reads the saved searches in the Activity’s onCreate method—this is acceptable only because the amount ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access