android.content.SharedPreferences |
Interface for accessing and modifying preference data returned by getSharedPreferences(String, int). For any particular set of preferences, there is a single instance of this class that all clients share. Modifications to the preferences must go through an SharedPreferences.Editor object to ensure the preference values remain in a consistent state and control when they are committed to storage.
Note: currently this class does not support use across multiple processes. This will be added later.
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
SharedPreferences.Editor | Interface used for modifying values in a SharedPreferences object. | ||||||||||
SharedPreferences.OnSharedPreferenceChangeListener | Interface definition for a callback to be invoked when a shared preference is changed. |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Checks whether the preferences contains a preference.
| |||||||||||
Create a new Editor for these preferences, through which you can make
modifications to the data in the preferences and atomically commit those
changes back to the SharedPreferences object.
| |||||||||||
Retrieve all values from the preferences.
| |||||||||||
Retrieve a boolean value from the preferences.
| |||||||||||
Retrieve a float value from the preferences.
| |||||||||||
Retrieve an int value from the preferences.
| |||||||||||
Retrieve a long value from the preferences.
| |||||||||||
Retrieve a String value from the preferences.
| |||||||||||
Registers a callback to be invoked when a change happens to a preference.
| |||||||||||
Unregisters a previous callback.
|
Checks whether the preferences contains a preference.
key | The name of the preference to check. |
---|
Create a new Editor for these preferences, through which you can make modifications to the data in the preferences and atomically commit those changes back to the SharedPreferences object.
Note that you must call commit() to have any changes you perform in the Editor actually show up in the SharedPreferences.
Retrieve all values from the preferences.
NullPointerException |
---|
Retrieve a boolean value from the preferences.
key | The name of the preference to retrieve. |
---|---|
defValue | Value to return if this preference does not exist. |
ClassCastException |
---|
Retrieve a float value from the preferences.
key | The name of the preference to retrieve. |
---|---|
defValue | Value to return if this preference does not exist. |
ClassCastException |
---|
Retrieve an int value from the preferences.
key | The name of the preference to retrieve. |
---|---|
defValue | Value to return if this preference does not exist. |
ClassCastException |
---|
Retrieve a long value from the preferences.
key | The name of the preference to retrieve. |
---|---|
defValue | Value to return if this preference does not exist. |
ClassCastException |
---|
Retrieve a String value from the preferences.
key | The name of the preference to retrieve. |
---|---|
defValue | Value to return if this preference does not exist. |
ClassCastException |
---|
Registers a callback to be invoked when a change happens to a preference.
listener | The callback that will run. |
---|
Unregisters a previous callback.
listener | The callback that should be unregistered. |
---|