Compartilhar via


Context.GetSharedPreferences(String, FileCreationMode) Method

Definition

Retrieve and hold the contents of the preferences file 'name', returning a SharedPreferences through which you can retrieve and modify its values.

[Android.Runtime.Register("getSharedPreferences", "(Ljava/lang/String;I)Landroid/content/SharedPreferences;", "GetGetSharedPreferences_Ljava_lang_String_IHandler")]
public abstract Android.Content.ISharedPreferences? GetSharedPreferences (string? name, Android.Content.FileCreationMode mode);
[<Android.Runtime.Register("getSharedPreferences", "(Ljava/lang/String;I)Landroid/content/SharedPreferences;", "GetGetSharedPreferences_Ljava_lang_String_IHandler")>]
abstract member GetSharedPreferences : string * Android.Content.FileCreationMode -> Android.Content.ISharedPreferences

Parameters

name
String

Desired preferences file.

mode
FileCreationMode

Operating mode.

Returns

The single SharedPreferences instance that can be used to retrieve and modify the preference values.

Attributes

Remarks

Retrieve and hold the contents of the preferences file 'name', returning a SharedPreferences through which you can retrieve and modify its values. Only one instance of the SharedPreferences object is returned to any callers for the same name, meaning they will see each other's edits as soon as they are made.

This method is thread-safe.

If the preferences directory does not already exist, it will be created when this method is called.

If a preferences file by this name does not exist, it will be created when you retrieve an editor (SharedPreferences#edit()) and then commit changes (SharedPreferences.Editor#commit() or SharedPreferences.Editor#apply()).

Java documentation for android.content.Context.getSharedPreferences(java.lang.String, int).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to