Sharepreference 简单工具类

2015/06/25 15:28
阅读数 27
package com.qiho.wheresmycar.util;

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

/**
 * 简单的xml数据操作类
 * 
 * @author sfshine
 * 
 */

public class DataStoreUtil {
	public static String datastore = "data";

	public static void put(Context context, String key, String value) {

		SharedPreferences settings = context.getSharedPreferences(datastore,
				Context.MODE_PRIVATE);
		SharedPreferences.Editor editor = settings.edit();
		editor.putString(key, value);

		editor.commit();
	}

	public static String getString(Context context, String key) {
		SharedPreferences settings = context.getSharedPreferences(datastore,
				Context.MODE_PRIVATE);

		String arg = settings.getString(key, "0");
		return arg;
	}

	public static void clear(Context context) {
		SharedPreferences settings = context.getSharedPreferences(datastore,
				Context.MODE_PRIVATE);
		SharedPreferences.Editor editor = settings.edit();
		editor.clear();
		editor.commit();
	}
}

展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部