/**
*
* SharedPreferences工具类,使用前必须先初始化,最好在Application的onCreate方法里初始化
*
* @author bingoogol@sina.com 2014-3-6
*/
public class SpUtil {
private static SpUtil instance = new SpUtil();
private static SharedPreferences mSp;
private SpUtil() {
}
public static SpUtil getInstance() {
return instance;
}
public static void init(Context context) {
mSp = context.getSharedPreferences(context.getResources().getString(R.string.sp_name), Context.MODE_PRIVATE);
}
public static void putString(String key, String value) {
Editor editor = mSp.edit();
editor.putString(key, value);
editor.commit();
}
public static String getString(String key, String defValue) {
return mSp.getString(key, defValue);
}
public static void putInt(String key, int value) {
Editor editor = mSp.edit();
editor.putInt(key, value);
editor.commit();
}
public static int getInt(String key, int defValue) {
return mSp.getInt(key, defValue);
}
}