User preferences
An application collects user preferences in two ways. In the first case, an application presents a settings screen to the user to choose preferences such as language, number of results to show per page, and so on. Such preferences are best stored using the Preference
class. The other case is when user preferences are picked up as the user navigates through the application. For example, when searching for a book, the user selects books by a particular author. An application might want to save such a preference for the next time when the user logs in. Such user preferences are best stored using SharedPreferences
. Under the hood, the Preference
class also calls SharedPreferences
. Please note that SharedPreferences
only persist primitive data types.
Shared preferences
The SharedPreferences
class is used to store primitive data types in a key-value pair. These primitive types include int
, long
, Boolean
, float
, string set
, and string
. Data stored in this SharedPreferences
persists...