Preferences

Preferences are implemented through use of the SharedPreferences class. A SharedPreferences object can be used to store primitive data (for example, integers and strings) in a key/value pair. Each value has its own key for storage and retrieval of that data. SharedPreferences are stored in memory private to the app and will persist as long as the app remains installed on the device. App upgrades will not impact the values stored with SharedPreferences.

There are two main modes for accessing SharedPreferences: getSharedPreferences("String preference name", integer mode) and getPreferences(integer mode). The getSharedPreferences mode is used when you want to have more than one set of preferences for an app, or you want the preferences ...

Get Learning Mobile App Development: A Hands-on Guide to Building Apps with iOS and Android 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.