首页 > 代码库 > SPUtils
SPUtils
package cn.itcast.demo; import android.content.Context; import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; import java.util.Map; public class SPUtils { private Context context; private SharedPreferences sp; private Editor editor; public SPUtil(Context context) { this.context = context; sp = this.context.getSharedPreferences("config", Context.MODE_APPEND); editor = sp.edit(); } public void getInstance(Context context, String filename) { this.context = context; sp = context.getSharedPreferences(filename, Context.MODE_APPEND); editor = sp.edit(); } public void putBoolean(String key, Boolean value) { editor.putBoolean(key, value); editor.commit(); } public boolean getBoolean(String key, Boolean defValue) { return sp.getBoolean(key, defValue); } public void putString(String key, String value) { if (key == null) { return; } editor.putString(key, value); editor.commit(); } public String getString(String key, String defValue) { return sp.getString(key, defValue); } public void putInt(String key, int value) { editor.putInt(key, value); editor.commit(); } public int getInt(String key, int defValue) { return sp.getInt(key, defValue); } public Map<String, ?> getAll() { return sp.getAll(); } }
SPUtils
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。