Back to project page CommonLibs.
The source code is released under:
Apache License
If you think the Android project CommonLibs listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.alex.common.utils; /*from w w w .j av a 2 s . c om*/ import android.content.Context; import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; /** * SharedPreferences????? * @author caisenchuan */ public class PrefUtils { /*-------------------------- * ??? *-------------------------*/ /*-------------------------- * ????? *-------------------------*/ /*-------------------------- * ???????? *-------------------------*/ /*-------------------------- * public?? *-------------------------*/ /** * ???????pref? * @param context ??? * @param pref_name share pref???? * @param tag ????? * @param value ??? */ public static void keep(Context context, String pref_name, String tag, String value) { SharedPreferences pref = context.getSharedPreferences(pref_name, Context.MODE_APPEND); Editor editor = pref.edit(); editor.putString(tag, value); editor.commit(); } /** * ???boolean?pref? * @param context ??? * @param pref_name share pref???? * @param tag ????? * @param value ??? */ public static void keep(Context context, String pref_name, String tag, boolean value) { SharedPreferences pref = context.getSharedPreferences(pref_name, Context.MODE_APPEND); Editor editor = pref.edit(); editor.putBoolean(tag, value); editor.commit(); } /** * ?pref???????? * @param context ??? * @param pref_name share pref???? * @param tag ????? */ public static String readString(Context context, String pref_name, String tag) { SharedPreferences pref = context.getSharedPreferences(pref_name, Context.MODE_APPEND); String ret = pref.getString(tag, ""); return ret; } /** * ?pref?????boolean * @param context ??? * @param pref_name share pref???? * @param tag ????? */ public static boolean readBoolean(Context context, String pref_name, String tag) { SharedPreferences pref = context.getSharedPreferences(pref_name, Context.MODE_APPEND); boolean ret = pref.getBoolean(tag, false); return ret; } /** * ?????? * @param context * @param pref_name share pref???? */ public static void clear(Context context, String pref_name) { SharedPreferences pref = context.getSharedPreferences(pref_name, Context.MODE_APPEND); Editor editor = pref.edit(); editor.clear(); editor.commit(); } /*-------------------------- * protected??packet?? *-------------------------*/ /*-------------------------- * private?? *-------------------------*/ }