Datasheet
Method Description
int getInt(String key, Returns the integer associated with a specified key. If the key
int def) does not exist, it is created with the default value def and this
default value is then returned.
long getLong(String key, Returns the long associated with a specified key. If the key does
long def) not exist, it is created with the default value def and this default
value is then returned.
Setting Preference Values on the Node
Along with each get method is a put version intended for setting the information associated with a
given configuration parameter’s key name.
Method Description
void put(String key, String value) These methods set a configuration
void putBoolean(String key, boolean value)
parameter (the name of which is passed
in as
key) to a specific type. If key or
void putByteArray(String key, byte[] value) value is null, an exception is thrown.
The key can be at most 80 characters long
void putDouble(String key, double value)
(defined in MAX_KEY_LENGTH) and the
void putInt(String key, int value) value can be at most 8,192 characters
void putFloat(String key, float value)
(defined in MAX_VALUE_LENGTH).
void putLong(String key, long value)
Events
Two events are defined for the Preference class — one fires when a node is changed in the preference
tree, and the second fires when a preference is changed. The methods for these events are listed in the
next table.
Method Description
void addNodeChangeListener Adds a listener for notification of when a
(NodeChangeListener ncl) child node is added or removed from the
current preference node.
void addPreferenceChangeListener Adds a listener for preference change
(PreferenceChangeListener pcl) events— anytime a preference is added
to, removed from, or the value is
changed, listeners will be notified.
void removeNodeChangeListener Removes a specified node change
(NodeChangeListener ncl) listener.
void removePreferenceChangeListener Removes a specified preference change
(PreferenceChangeListener pcl) listener.
73
Chapter 1: Key Java Language Features and Libraries
05_777106 ch01.qxp 11/28/06 10:43 PM Page 73