public class StorageUtil {public final static String STORAGE_FILE_NAME = "wangzhan.config";//存数据public static void putString(Context ctx , String key , String value){SharedPreferences sharePreference = getSharePreference(ctx);sharePreference.edit().putString(key, value).commit();}//取数据public static String getString(Context ctx , String key , String... defaultvalue){SharedPreferences sharePreference = getSharePreference(ctx);String dv = "";for (String v : defaultvalue) {dv = v;break;}return sharePreference.getString(key, dv);}private static SharedPreferences getSharePreference(Context ctx){return ctx.getSharedPreferences(STORAGE_FILE_NAME, Context.MODE_PRIVATE);}//存boolean数据public static void putBoolean(Context ctx , String key , boolean value){SharedPreferences sharePreference = getSharePreference(ctx);sharePreference.edit().putBoolean(key, value).commit();}//取boolean数据public static boolean getBoolen(Context ctx , String key , boolean... defaultvalue){SharedPreferences sharePreference = getSharePreference(ctx);boolean dv = false;for (boolean v : defaultvalue) {dv = v;break;}return sharePreference.getBoolean(key, dv);}
}