PreferenceManager
open classPreferenceManager
kotlin.Any | |
↳ | android.preference.PreferenceManager |
Used to help create Preference
hierarchies from activities or XML.
In most cases, clients should use PreferenceActivity.addPreferencesFromIntent
or PreferenceActivity.addPreferencesFromResource(int)
.
Summary
Nested classes | |
---|---|
abstract |
Interface definition for a class that will be called when the container's activity is destroyed. |
abstract |
Interface definition for a class that will be called when the container's activity receives an activity result. |
abstract |
Interface definition for a class that will be called when the container's activity is stopped. |
Constants | |
---|---|
static String | |
static String |
The Activity meta-data key for its XML preference hierarchy. |
Public methods | |
---|---|
open PreferenceScreen! |
createPreferenceScreen(context: Context!) |
open Preference? |
findPreference(key: CharSequence!) Finds a |
open static SharedPreferences! |
Gets a |
open static String! |
Returns the name used for storing default shared preferences. |
open PreferenceDataStore? |
Returns the |
open SharedPreferences! |
Gets a |
open Int |
Returns the current mode of the SharedPreferences file that preferences managed by this will use. |
open String! |
Returns the current name of the SharedPreferences file that preferences managed by this will use. |
open Boolean |
Indicates if the storage location used internally by this class is the default provided by the hosting |
open Boolean |
Indicates if the storage location used internally by this class is backed by device-protected storage. |
open static Unit |
setDefaultValues(context: Context!, resId: Int, readAgain: Boolean) Sets the default values from an XML preference file by reading the values defined by each |
open static Unit |
Similar to |
open Unit |
setPreferenceDataStore(dataStore: PreferenceDataStore!) Sets a |
open Unit |
Sets the mode of the SharedPreferences file that preferences managed by this will use. |
open Unit |
Sets the name of the SharedPreferences file that preferences managed by this will use. |
open Unit |
Sets the storage location used internally by this class to be the default provided by the hosting |
open Unit |
Explicitly set the storage location used internally by this class to be device-protected storage. |
Constants
KEY_HAS_SET_DEFAULT_VALUES
static valKEY_HAS_SET_DEFAULT_VALUES: String
Deprecated: Deprecated in Java.
Value: "_has_set_default_values"
METADATA_KEY_PREFERENCES
static valMETADATA_KEY_PREFERENCES: String
Deprecated: Deprecated in Java.
The Activity meta-data key for its XML preference hierarchy.
Value: "android.preference"
Public methods
createPreferenceScreen
open funcreatePreferenceScreen(context: Context!): PreferenceScreen!
Deprecated: Deprecated in Java.
findPreference
open funfindPreference(key: CharSequence!): Preference?
Deprecated: Deprecated in Java.
Finds a Preference
based on its key.
Parameters | |
---|---|
key |
CharSequence!: the key of the preference to retrieve |
Return | |
---|---|
Preference? |
the Preference with the key, or null |
getDefaultSharedPreferences
open static fungetDefaultSharedPreferences(: Context!): SharedPreferences!
Deprecated: Deprecated in Java.
Gets a SharedPreferences
instance that points to the default file that is used by the preference framework in the given context.
Parameters | |
---|---|
context |
Context!: The context of the preferences whose values are wanted. |
Return | |
---|---|
SharedPreferences! |
A SharedPreferences instance that can be used to retrieve and listen to values of the preferences. |
getDefaultSharedPreferencesName
open static fungetDefaultSharedPreferencesName(: Context!): String!
Deprecated: Deprecated in Java.
Returns the name used for storing default shared preferences.
getPreferenceDataStore
open fungetPreferenceDataStore(): PreferenceDataStore?
Deprecated: Deprecated in Java.
Returns the PreferenceDataStore
associated with this manager or null
if the default android.content.SharedPreferences
are used instead.
Return | |
---|---|
PreferenceDataStore? |
The PreferenceDataStore associated with this manager or null if none. |
getSharedPreferences
open fungetSharedPreferences(): SharedPreferences!
Deprecated: Deprecated in Java.
Gets a SharedPreferences
instance that preferences managed by this will use.
Return | |
---|---|
SharedPreferences! |
a SharedPreferences instance pointing to the file that contains the values of preferences that are managed by this PreferenceManager. If a PreferenceDataStore has been set, this method returns null . |
getSharedPreferencesMode
open fungetSharedPreferencesMode(): Int
Deprecated: Deprecated in Java.
Returns the current mode of the SharedPreferences file that preferences managed by this will use.
Return | |
---|---|
Int |
The mode that can be passed to Context.getSharedPreferences(String, int) . |
getSharedPreferencesName
open fungetSharedPreferencesName(): String!
Deprecated: Deprecated in Java.
Returns the current name of the SharedPreferences file that preferences managed by this will use.
Return | |
---|---|
String! |
The name that can be passed to Context.getSharedPreferences(String, int) . |
isStorageDefault
open funisStorageDefault(): Boolean
Deprecated: Deprecated in Java.
Indicates if the storage location used internally by this class is the default provided by the hosting Context
.
isStorageDeviceProtected
open funisStorageDeviceProtected(): Boolean
Deprecated: Deprecated in Java.
Indicates if the storage location used internally by this class is backed by device-protected storage.
setDefaultValues
open static funsetDefaultValues(
context: Context!,
resId: Int,
readAgain: Boolean
): Unit
Deprecated: Deprecated in Java.
Sets the default values from an XML preference file by reading the values defined by each Preference
item's android:defaultValue
attribute. This should be called by the application's main activity.
Parameters | |
---|---|
context |
Context!: The context of the shared preferences. |
resId |
Int: The resource ID of the preference XML file. |
readAgain |
Boolean: Whether to re-read the default values. If false, this method sets the default values only if this method has never been called in the past (or if the KEY_HAS_SET_DEFAULT_VALUES in the default value shared preferences file is false). To attempt to set the default values again bypassing this check, set readAgain to true.
Note: this will NOT reset preferences back to their default values. For that functionality, use |
setDefaultValues
open static funsetDefaultValues(
context: Context!,
: String!,
: Int,
resId: Int,
readAgain: Boolean
): Unit
Deprecated: Deprecated in Java.
Similar to setDefaultValues(android.content.Context,int,boolean)
but allows the client to provide the filename and mode of the shared preferences file.
Parameters | |
---|---|
context |
Context!: The context of the shared preferences. |
sharedPreferencesName |
String!: A custom name for the shared preferences file. |
sharedPreferencesMode |
Int: The file creation mode for the shared preferences file, such as android.content.Context#MODE_PRIVATE or android.content.Context#MODE_PRIVATE |
resId |
Int: The resource ID of the preference XML file. |
readAgain |
Boolean: Whether to re-read the default values. If false, this method will set the default values only if this method has never been called in the past (or if the KEY_HAS_SET_DEFAULT_VALUES in the default value shared preferences file is false). To attempt to set the default values again bypassing this check, set readAgain to true.
Note: this will NOT reset preferences back to their default values. For that functionality, use |
setPreferenceDataStore
open funsetPreferenceDataStore(dataStore: PreferenceDataStore!): Unit
Deprecated: Deprecated in Java.
Sets a PreferenceDataStore
to be used by all Preferences associated with this manager that don't have a custom PreferenceDataStore
assigned via Preference.setPreferenceDataStore(PreferenceDataStore)
. Also if the data store is set, the child preferences won't use android.content.SharedPreferences
as long as they are assigned to this manager.
Parameters | |
---|---|
dataStore |
PreferenceDataStore!: The PreferenceDataStore to be used by this manager. |
setSharedPreferencesMode
open funsetSharedPreferencesMode(: Int): Unit
Deprecated: Deprecated in Java.
Sets the mode of the SharedPreferences file that preferences managed by this will use.
Parameters | |
---|---|
sharedPreferencesMode |
Int: The mode of the SharedPreferences file. |
setSharedPreferencesName
open funsetSharedPreferencesName(: String!): Unit
Deprecated: Deprecated in Java.
Sets the name of the SharedPreferences file that preferences managed by this will use.
If custom PreferenceDataStore
is set, this won't override its usage.
Parameters | |
---|---|
sharedPreferencesName |
String!: The name of the SharedPreferences file. |
setStorageDefault
open funsetStorageDefault(): Unit
Deprecated: Deprecated in Java.
Sets the storage location used internally by this class to be the default provided by the hosting Context
.
setStorageDeviceProtected
open funsetStorageDeviceProtected(): Unit
Deprecated: Deprecated in Java.
Explicitly set the storage location used internally by this class to be device-protected storage.
On devices with direct boot, data stored in this location is encrypted with a key tied to the physical device, and it can be accessed immediately after the device has booted successfully, both before and after the user has authenticated with their credentials (such as a lock pattern or PIN).
Because device-protected data is available without user authentication, you should carefully limit the data you store using this Context. For example, storing sensitive authentication tokens or passwords in the device-protected area is strongly discouraged.