List of usage examples for android.content SharedPreferences edit
Editor edit();
From source file:Main.java
/** * Called to save supplied value in shared preferences against given key. * * @param context Context of caller activity * @param key Key of value to save against * @param value Value to save/*from www . j ava 2 s. c o m*/ */ public static void saveToPrefs(Context context, String key, String value) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); final SharedPreferences.Editor editor = prefs.edit(); editor.putString(key, value); editor.commit(); }
From source file:Main.java
/** * Store fired alert info in the SharedPrefs. *//*from www . ja v a 2 s . c o m*/ static void setAlertFiredInSharedPrefs(Context context, long eventId, long beginTime, long alarmTime) { // Store alarm time as the value too so we don't have to parse all the keys to flush // old alarms out of the table later. SharedPreferences prefs = getFiredAlertsTable(context); SharedPreferences.Editor editor = prefs.edit(); editor.putLong(getFiredAlertsKey(eventId, beginTime, alarmTime), alarmTime); editor.apply(); }
From source file:Main.java
private static void saveChannelBySharedPreferences(Context context, String channel) { SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences.Editor editor = sp.edit(); editor.putString(CHANNEL_KEY, channel); editor.putInt(CHANNEL_VERSION_KEY, getVersionCode(context)); editor.commit();/*from w w w. j a v a 2 s. c om*/ }
From source file:Main.java
public static boolean saveArray(Context mContext) { SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mContext); SharedPreferences.Editor mEdit1 = sp.edit(); mEdit1.putInt("Like_size", mDishLikeList.size()); for (int i = 0; i < mDishLikeList.size(); i++) { mEdit1.remove("Like_" + i); mEdit1.putString("Like_" + i, mDishLikeList.get(i)); }/*from w ww . j ava2 s. com*/ return mEdit1.commit(); }
From source file:Main.java
public static void savePreferencesForReasonCode(Context context, String key, String value) { SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences.Editor editor = sharedPreferences.edit(); editor.putString(key, value);/*from w w w. ja v a 2 s .c o m*/ editor.commit(); }
From source file:Main.java
public static void setSessionField(Activity activity, String field, String value) { SharedPreferences sharedPref = activity.getSharedPreferences("Session", Context.MODE_PRIVATE); SharedPreferences.Editor editor = sharedPref.edit(); editor.putString(field, value);//from w w w .java 2 s.com editor.commit(); }
From source file:Main.java
/** * Utility method to flag when the cloud session has been created for the * last time. This time is used to check Oauth timeout. * // w w w . java 2 s . c o m * @param context */ public static void saveLastCloudLoadingTime(Context context) { SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context); Editor editor = sharedPref.edit(); editor.putLong(KEY_CLOUD_LOADING_TIME, new Date().getTime()); editor.commit(); }
From source file:Main.java
public final static void removeUserPreferences(Activity context) { SharedPreferences sharedPref = context.getSharedPreferences("currentUser", Context.MODE_PRIVATE); SharedPreferences.Editor editor = sharedPref.edit(); editor.clear();//from w w w .ja v a 2 s . c om editor.commit(); }
From source file:Main.java
public static void putJPushID(Context context, String value) { SharedPreferences sharedPreferences = context.getSharedPreferences(JPushID, Context.MODE_PRIVATE); SharedPreferences.Editor edit = sharedPreferences.edit(); edit.putString(JPushID_K, value);/*from w ww.j ava 2s . c o m*/ edit.commit(); }
From source file:Main.java
public static void putStrogeB(Context context, boolean value) { SharedPreferences sharedPreferences = context.getSharedPreferences(StrogeB, Context.MODE_PRIVATE); SharedPreferences.Editor edit = sharedPreferences.edit(); edit.putBoolean(StrogeB_K, value);// w ww . j a va 2 s . c o m edit.commit(); }