List of usage examples for android.content SharedPreferences edit
Editor edit();
From source file:Main.java
public static void setBooleanPref(Context context, String name, boolean value) { SharedPreferences prefs = context.getSharedPreferences(APPLICATION_NAME, Context.MODE_PRIVATE); Editor ed = prefs.edit(); ed.putBoolean(name, value);//from www . ja va 2s . c o m ed.commit(); }
From source file:Main.java
public static void setGcmKey(final Context context, final String accountName, final String gcmKey) { SharedPreferences sp = getSharedPreferences(context); sp.edit().putString(makeAccountSpecificPrefKey(accountName, PREFIX_PREF_GCM_KEY), gcmKey).apply(); Log.d("GoogleAcount", "GCM key of account " + accountName + " set to: " + sanitizeGcmKey(gcmKey)); }
From source file:Main.java
public static void setBindStr(Context context, String bindStr, String strValue) { SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context); Editor editor = sp.edit(); editor.putString(bindStr, strValue); editor.commit();/* w w w . j a va 2 s. c o m*/ }
From source file:Main.java
public static void editUserInfo(Context context, String userLevel, String userDeposit, String userKbi, String userScore, String userCidiograph) { SharedPreferences perferences = context.getSharedPreferences(USER_INFO_OTHER, Context.MODE_PRIVATE); perferences.edit().putString(USER_LEVEL, userLevel).putString(USER_DEPOSIT, userDeposit) .putString(USER_KBI, userKbi).putString(USER_SCORE, userScore) .putString(USER_CIDIOGRAPH, userCidiograph).commit(); }
From source file:Main.java
public static void save(Context context, String sp_name, String key, Object value) { SharedPreferences sp = context.getSharedPreferences(sp_name, 0); if (value instanceof String) { sp.edit().putString(key, (String) value).commit(); } else if (value instanceof Integer) { sp.edit().putInt(key, (Integer) value).commit(); }/*from ww w . j a v a 2 s . co m*/ }
From source file:Main.java
public static void savePreferencesInt(String key, int value, Context context) { SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); Editor editor = sharedPreferences.edit(); editor.putInt(key, value);//from ww w .j av a 2 s . com editor.commit(); }
From source file:Main.java
public static void writeSharedPreferences(Context context, String prefsName, String name, Object value) { if (name == null || value == null) { return;//from w ww. jav a 2s .c om } SharedPreferences user = context.getSharedPreferences(prefsName, 0); Editor editor = user.edit(); if (value instanceof Integer) { editor.putInt(name, Integer.parseInt(value.toString())); } else if (value instanceof Long) { editor.putLong(name, Long.parseLong(value.toString())); } else if (value instanceof Boolean) { editor.putBoolean(name, Boolean.parseBoolean(value.toString())); } else if (value instanceof String) { editor.putString(name, value.toString()); } else if (value instanceof Float) { editor.putFloat(name, Float.parseFloat(value.toString())); } editor.commit(); }
From source file:Main.java
public static void savePreferences(String key, String value, Context context) { SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); Editor editor = sharedPreferences.edit(); editor.putString(key, value);//from w w w.j av a2s .c o m editor.commit(); }
From source file:Main.java
public static void saveStringToSharePrefs(Context context, String fileName, String key, String value) { SharedPreferences preferences = context.getSharedPreferences(fileName, Context.MODE_PRIVATE); Editor editor = preferences.edit(); editor.putString(key, value);/*from w ww . ja v a 2 s.co m*/ editor.commit(); }
From source file:Main.java
public static boolean setPrefrence(SharedPreferences pref, String key, String value) { try {/* w w w . jav a 2 s. c o m*/ SharedPreferences.Editor editor = pref.edit(); editor.putString(key, value); editor.commit(); return true; } catch (Exception ex) { return false; } }