共用方式為


ISharedPreferencesOnSharedPreferenceChangeListener.OnSharedPreferenceChanged Method

Definition

Called when a shared preference is changed, added, or removed.

[Android.Runtime.Register("onSharedPreferenceChanged", "(Landroid/content/SharedPreferences;Ljava/lang/String;)V", "GetOnSharedPreferenceChanged_Landroid_content_SharedPreferences_Ljava_lang_String_Handler:Android.Content.ISharedPreferencesOnSharedPreferenceChangeListenerInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null")]
public void OnSharedPreferenceChanged (Android.Content.ISharedPreferences? sharedPreferences, string? key);
[<Android.Runtime.Register("onSharedPreferenceChanged", "(Landroid/content/SharedPreferences;Ljava/lang/String;)V", "GetOnSharedPreferenceChanged_Landroid_content_SharedPreferences_Ljava_lang_String_Handler:Android.Content.ISharedPreferencesOnSharedPreferenceChangeListenerInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null")>]
abstract member OnSharedPreferenceChanged : Android.Content.ISharedPreferences * string -> unit

Parameters

sharedPreferences
ISharedPreferences

The SharedPreferences that received the change.

key
String

The key of the preference that was changed, added, or removed. Apps targeting android.os.Build.VERSION_CODES#R on devices running OS versions android.os.Build.VERSION_CODES#R Android R or later, will receive a null value when preferences are cleared.

Attributes

Remarks

Called when a shared preference is changed, added, or removed. This may be called even if a preference is set to its existing value.

This callback will be run on your main thread.

<em>Note: This callback will not be triggered when preferences are cleared via Editor#clear(), unless targeting android.os.Build.VERSION_CODES#R on devices running OS versions android.os.Build.VERSION_CODES#R Android R or later.</em>

Java documentation for android.content.SharedPreferences.OnSharedPreferenceChangeListener.onSharedPreferenceChanged(android.content.SharedPreferences, java.lang.String).

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