List of usage examples for android.content SharedPreferences edit
Editor edit();
From source file:Main.java
public static void writeCameraId(Context context, String value) { SharedPreferences preferences = context.getSharedPreferences("CameraConfig", Context.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); editor.putString("camera", value); editor.commit();/*from w w w. j a v a 2 s . c o m*/ }
From source file:Main.java
public static void SavePreferences(Context context, String key) { SharedPreferences sharedPreferences = context.getSharedPreferences(TOKEN, Context.MODE_PRIVATE); SharedPreferences.Editor editor = sharedPreferences.edit(); editor.putString(key, token);/*from ww w .j a va 2 s. c o m*/ editor.apply(); }
From source file:Main.java
public static void saveToPreferences(Context context, String key, String message) { SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); Editor edit = sharedPreferences.edit(); edit.putString(key, message);// ww w . jav a 2s . co m edit.commit(); }
From source file:Main.java
public static boolean putBoolean(Context context, String key, boolean value) { SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE); SharedPreferences.Editor editor = settings.edit(); editor.putBoolean(key, value);// w ww . ja va 2s. c om return editor.commit(); }
From source file:Main.java
public static boolean putString(Context context, String key, String value) { SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE); SharedPreferences.Editor editor = settings.edit(); editor.putString(key, value);/*from w w w. j a va2 s .c om*/ return editor.commit(); }
From source file:Main.java
public static boolean putLong(Context context, String key, long value) { SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE); SharedPreferences.Editor editor = settings.edit(); editor.putLong(key, value);//from w w w . ja v a 2 s .c om return editor.commit(); }
From source file:Main.java
public static void removePreference(Context context, final String key) { final SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context); if (settings.contains(key)) { settings.edit().remove(key).commit(); }/*from www.j a va 2s . c o m*/ }
From source file:Main.java
public static void logout(Context context) { SharedPreferences preferences = context.getSharedPreferences("MyPrefs", Context.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); editor.clear();/*from w w w . ja v a2 s . c o m*/ editor.commit(); NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); manager.cancelAll(); }
From source file:Main.java
public static void saveDataToSharedPref(Context context, List<String> arrayList) { SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences.Editor editor = sharedPrefs.edit(); Gson gson = new Gson(); String json = gson.toJson(arrayList); editor.putString(APP_LIST, json);/*from ww w . j av a 2 s.c o m*/ editor.commit(); }