Udostępnij za pośrednictwem


Preferences.GetInt(String, Int32) Method

Definition

Returns the int value represented by the string associated with the specified key in this preference node.

[Android.Runtime.Register("getInt", "(Ljava/lang/String;I)I", "GetGetInt_Ljava_lang_String_IHandler")]
public abstract int GetInt (string? key, int def);
[<Android.Runtime.Register("getInt", "(Ljava/lang/String;I)I", "GetGetInt_Ljava_lang_String_IHandler")>]
abstract member GetInt : string * int -> int

Parameters

key
String

key whose associated value is to be returned as an int.

def
Int32

the value to be returned in the event that this preference node has no value associated with key or the associated value cannot be interpreted as an int, or the backing store is inaccessible.

Returns

the int value represented by the string associated with key in this preference node, or def if the associated value does not exist or cannot be interpreted as an int.

Attributes

Exceptions

if this node has been removed.

if the parameter key is null.

Remarks

Returns the int value represented by the string associated with the specified key in this preference node. The string is converted to an integer as by Integer#parseInt(String). Returns the specified default if there is no value associated with the key, the backing store is inaccessible, or if Integer.parseInt(String) would throw a NumberFormatException if the associated value were passed. This method is intended for use in conjunction with #putInt.

If the implementation supports stored defaults and such a default exists, is accessible, and could be converted to an int with Integer.parseInt, this int is returned in preference to the specified default.

Java documentation for java.util.prefs.Preferences.getInt(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