/**
* 轻量级文件存储
* @author 张鹏飞
*
*/
public class PreferenceUtil {
/** 名称:首选项名称 */
public static final String NAME_PREFERENCE = "labrary_preference";
private SharedPreferences mSharedPreferences;
private Editor mEditor;
public void onDestroy() {
mSharedPreferences = null;
mEditor = null;
}
public PreferenceUtil(Context c) {
mSharedPreferences = c.getSharedPreferences(NAME_PREFERENCE, 0);
mEditor = mSharedPreferences.edit();
}
public void setLong(String key, long l) {
mEditor.putLong(key, l);
mEditor.commit();
}
public long getLong(String key, long defaultlong) {
return mSharedPreferences.getLong(key, defaultlong);
}
public void setBoolean(String key, boolean value) {
mEditor.putBoolean(key, value);
mEditor.commit();
}
public boolean getBoolean(String key, Boolean defaultboolean) {
return mSharedPreferences.getBoolean(key, defaultboolean);
}
public void setInt(String key, int value) {
mEditor.putInt(key, value);
mEditor.commit();
}
public int getInt(String key, int defaultInt) {
return mSharedPreferences.getInt(key, defaultInt);
}
public String getString(String key) {
return mSharedPreferences.getString(key,"");
}
public void setString(String key, String value) {
mEditor.putString(key, value);
mEditor.commit();
}
public void remove(String key) {
mEditor.remove(key);
mEditor.commit();
}
* 轻量级文件存储
* @author 张鹏飞
*
*/
public class PreferenceUtil {
/** 名称:首选项名称 */
public static final String NAME_PREFERENCE = "labrary_preference";
private SharedPreferences mSharedPreferences;
private Editor mEditor;
public void onDestroy() {
mSharedPreferences = null;
mEditor = null;
}
public PreferenceUtil(Context c) {
mSharedPreferences = c.getSharedPreferences(NAME_PREFERENCE, 0);
mEditor = mSharedPreferences.edit();
}
public void setLong(String key, long l) {
mEditor.putLong(key, l);
mEditor.commit();
}
public long getLong(String key, long defaultlong) {
return mSharedPreferences.getLong(key, defaultlong);
}
public void setBoolean(String key, boolean value) {
mEditor.putBoolean(key, value);
mEditor.commit();
}
public boolean getBoolean(String key, Boolean defaultboolean) {
return mSharedPreferences.getBoolean(key, defaultboolean);
}
public void setInt(String key, int value) {
mEditor.putInt(key, value);
mEditor.commit();
}
public int getInt(String key, int defaultInt) {
return mSharedPreferences.getInt(key, defaultInt);
}
public String getString(String key) {
return mSharedPreferences.getString(key,"");
}
public void setString(String key, String value) {
mEditor.putString(key, value);
mEditor.commit();
}
public void remove(String key) {
mEditor.remove(key);
mEditor.commit();
}