Sdílet prostřednictvím


Preference.OnSetInitialValue(Boolean, Object) Method

Definition

Implement this to set the initial value of the Preference.

[Android.Runtime.Register("onSetInitialValue", "(ZLjava/lang/Object;)V", "GetOnSetInitialValue_ZLjava_lang_Object_Handler")]
protected virtual void OnSetInitialValue (bool restorePersistedValue, Java.Lang.Object? defaultValue);
[<Android.Runtime.Register("onSetInitialValue", "(ZLjava/lang/Object;)V", "GetOnSetInitialValue_ZLjava_lang_Object_Handler")>]
abstract member OnSetInitialValue : bool * Java.Lang.Object -> unit
override this.OnSetInitialValue : bool * Java.Lang.Object -> unit

Parameters

restorePersistedValue
Boolean

True to restore the persisted value; false to use the given <var>defaultValue</var>.

defaultValue
Object

The default value for this Preference. Only use this if <var>restorePersistedValue</var> is false.

Attributes

Remarks

Implement this to set the initial value of the Preference.

If <var>restorePersistedValue</var> is true, you should restore the Preference value from the android.content.SharedPreferences. If <var>restorePersistedValue</var> is false, you should set the Preference value to defaultValue that is given (and possibly store to SharedPreferences if #shouldPersist() is true).

In case of using PreferenceDataStore, the <var>restorePersistedValue</var> is always true. But the default value (if provided) is set.

This may not always be called. One example is if it should not persist but there is no default value given.

Java documentation for android.preference.Preference.onSetInitialValue(boolean, java.lang.Object).

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