public class PreferenceUtil {
public static void write(Context context, String key, String value) {
SharedPreferences sharedPreferences = context.getSharedPreferences(
Constant.APP_NAME, Context.MODE_PRIVATE);
sharedPreferences.edit().putString(key, value).commit();
}
public static void write(Context context, String key, int value) {
SharedPreferences sharedPreferences = context.getSharedPreferences(
Constant.APP_NAME, Context.MODE_PRIVATE);
sharedPreferences.edit().putInt(key, value).commit();
}
public static void write(Context context, String key, Boolean value) {
SharedPreferences sharedPreferences = context.getSharedPreferences(
Constant.APP_NAME, Context.MODE_PRIVATE);
sharedPreferences.edit().putBoolean(key, value).commit();
}
public static String readString(Context context, String key) {
SharedPreferences sharedPreferences = context.getSharedPreferences(
Constant.APP_NAME, Context.MODE_PRIVATE);
return sharedPreferences.getString(key, "");
}
public static int readInt(Context context, String key) {
SharedPreferences sharedPreferences = context.getSharedPreferences(
Constant.APP_NAME, Context.MODE_PRIVATE);
return sharedPreferences.getInt(key, 0);
}
public static Boolean readBoolean(Context context, String key) {
SharedPreferences sharedPreferences = context.getSharedPreferences(
Constant.APP_NAME, Context.MODE_PRIVATE);
return sharedPreferences.getBoolean(key, false);
}
public static void remove(Context context, String key) {
SharedPreferences sharedPreferences = context.getSharedPreferences(
Constant.APP_NAME, Context.MODE_PRIVATE);
sharedPreferences.edit().remove(key).commit();
}
public static void write(Context context, String key, ArrayList
{
SharedPreferences sharedPreferences = context.getSharedPreferences(key,
Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putInt(key+"size",value.size());
for (int i = 0; i < value.size(); i++) {
editor.remove(key+i);
editor.putString(key + i, value.get(i));
}
editor.commit();
}
public static ArrayList
SharedPreferences sharedPreferences = context.getSharedPreferences(key,
context.MODE_PRIVATE);
ArrayList
int size = sharedPreferences.getInt(key+"size", 0);
for(int i=0;i
}
return list;
}
public static void clear(Context context, String key)
{
SharedPreferences sharedPreferences = context.getSharedPreferences(key,
Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.clear();
editor.commit();
}
}