您的位置:首页 > Web前端

SharedPreferenceUtils

2016-04-26 15:31 344 查看
(转载)http://ztelovecly.cn/?p=153

package com.miaoqu.coffee_app.utils;

import android.content.Context;
import android.content.SharedPreferences;

/**
* SharedPreference工具类
* Created by Administrator on 2015/8/3.
*/
public class SharedPreferenceUtils {
public final static String SETTING = "Setting";

public static void putValue(Context context, String key, int value) {
SharedPreferences.Editor sp = context.getSharedPreferences(SETTING, Context.MODE_PRIVATE).edit();
sp.putInt(key, value);
sp.commit();
}

public static void putValue(Context context, String key, boolean value) {
SharedPreferences.Editor sp = context.getSharedPreferences(SETTING, Context.MODE_PRIVATE).edit();
sp.putBoolean(key, value);
sp.commit();
}

public static void putValue(Context context, String key, String value) {
SharedPreferences.Editor sp = context.getSharedPreferences(SETTING, Context.MODE_PRIVATE).edit();
sp.putString(key, value);
sp.commit();
}

public static int getValue(Context context, String key, int defValue) {
SharedPreferences sp = context.getSharedPreferences(SETTING, Context.MODE_PRIVATE);
int value = sp.getInt(key, defValue);
return value;
}

public static boolean getValue(Context context, String key, boolean defValue) {
SharedPreferences sp = context.getSharedPreferences(SETTING, Context.MODE_PRIVATE);
boolean value = sp.getBoolean(key, defValue);
return value;
}

public static String getValue(Context context, String key, String defValue) {
SharedPreferences sp = context.getSharedPreferences(SETTING, Context.MODE_PRIVATE);
String value = sp.getString(key, defValue);
return value;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: