public class PreferencesUtils {
private Context context;
public PreferencesUtils(Context context) {
this.context = context;
}
public boolean putInt(String key, int value) {
boolean flag = context.getSharedPreferences(Constant.PREFERENCE_NAME, Context.MODE_PRIVATE).edit().putInt(key, value).commit();
return flag;
}
public int getInt(String key, int defValue) {
return context.getSharedPreferences(Constant.PREFERENCE_NAME, Context.MODE_PRIVATE).getInt(key, defValue);
}
public boolean putLong(String key, long value) {
boolean flag = context.getSharedPreferences(Constant.PREFERENCE_NAME, Context.MODE_PRIVATE).edit().putLong(key, value).commit();
return flag;
}
public long getLong(String key, long defValue) {
return context.getSharedPreferences(Constant.PREFERENCE_NAME, Context.MODE_PRIVATE).getLong(key, defValue);
}
public boolean putString(String key, String value) {
return context.getSharedPreferences(Constant.PREFERENCE_NAME, Context.MODE_PRIVATE).edit().putString(key, value).commit();
}
public String getString(String key, String defValue) {
return context.getSharedPreferences(Constant.PREFERENCE_NAME, Context.MODE_PRIVATE).getString(key, defValue);
}
public boolean putBoolean(String key, boolean value) {
return context.getSharedPreferences(Constant.PREFERENCE_NAME, Context.MODE_PRIVATE).edit().putBoolean(key, value).commit();
}
public boolean getBoolean(String key, boolean defValue) {
return context.getSharedPreferences(Constant.PREFERENCE_NAME, Context.MODE_PRIVATE).getBoolean(key, defValue);
}
public boolean clearAllValue() {
return context.getSharedPreferences(Constant.PREFERENCE_NAME, Context.MODE_PRIVATE).edit().clear().commit();
}
}
PreferencesUtils工具類,簡化preference操作
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。
相關(guān)閱讀更多精彩內(nèi)容
- 初衷 眾所周知,在OC時代,MJ大神使用一句宏定義MJCodingImplementation就搞定了歸解檔中繁瑣...
- 封裝了增刪改查功能適用于MySQL、Oracle、SQLServer、DB2、Sybase、JTDS、Postgr...
- EasyDB 基于ORMLite封裝的數(shù)據(jù)庫操作工具類——致力于最簡潔的數(shù)據(jù)庫操作API 功能點 支持自定義數(shù)據(jù)庫...