获得偏好值
Preferences
节点的值可以是 String
,boolean
,byte[]
,double
,float
,int
或 long
的类型。如果 Preferences
节点中不存在指定的值,则所有调用都必须提供默认值。
Preferences preferences = Preferences.userNodeForPackage(getClass());
String someString = preferences.get("someKey", "this is the default value");
boolean someBoolean = preferences.getBoolean("someKey", true);
byte[] someByteArray = preferences.getByteArray("someKey", new byte[0]);
double someDouble = preferences.getDouble("someKey", 887284.4d);
float someFloat = preferences.getFloat("someKey", 38723.3f);
int someInt = preferences.getInt("someKey", 13232);
long someLong = preferences.getLong("someKey", 2827637868234L);