Example usage for android.content SharedPreferences edit

List of usage examples for android.content SharedPreferences edit

Introduction

In this page you can find the example usage for android.content SharedPreferences edit.

Prototype

Editor edit();

Source Link

Document

Create a new Editor for these preferences, through which you can make modifications to the data in the preferences and atomically commit those changes back to the SharedPreferences object.

Usage

From source file:Main.java

public static boolean setActiveAccount(final Context context, final String accountName) {
    SharedPreferences sp = getSharedPreferences(context);
    sp.edit().putString(PREF_ACTIVE_ACCOUNT, accountName).apply();
    return true;/* w  w  w.  ja va  2 s .  co m*/
}

From source file:Main.java

public static void putInt(Context context, String key, int value, String spName) {
    SharedPreferences sp = getSharedPreferences(context, spName);
    sp.edit().putInt(key, value).apply();

}

From source file:Main.java

public static void setStringSharedPerference(SharedPreferences sp, String key, String value) {
    Editor editor = sp.edit();
    editor.putString(key, value);/*from  w w w.  j a  va  2  s.c  om*/
    editor.commit();
}

From source file:Main.java

public static void setBooleanSharedPerference(SharedPreferences sp, String key, boolean value) {
    Editor editor = sp.edit();
    editor.putBoolean(key, value);//from w w w  .ja  v a  2s .co  m
    editor.commit();
}

From source file:Main.java

public static void clearPreference(Context context, final SharedPreferences p) {
    final SharedPreferences.Editor editor = p.edit();
    editor.clear();/*from   w w w  .  ja va 2s . c  o m*/
    editor.apply();
}

From source file:Main.java

public static void clearPreference(Context context, final SharedPreferences p) {
    final SharedPreferences.Editor editor = p.edit();
    editor.clear();/*from w  w  w  .j av a  2  s .com*/
    editor.commit();
}

From source file:Main.java

public static boolean save(Context context, String key, String value) {
    SharedPreferences sp = context.getSharedPreferences("app", 0);
    return sp.edit().putString(key, value).commit();
}

From source file:Main.java

public static void setSPValue(Context context, String strKey, String strValue) {
    SharedPreferences exam_info = context.getSharedPreferences("exam", 0);
    exam_info.edit().putString(strKey, strValue).commit();
}

From source file:Main.java

public static void setLValue(Context context, String strKey, long value) {

    SharedPreferences exam_info = context.getSharedPreferences("exam", 0);
    exam_info.edit().putLong(strKey, value).commit();
}

From source file:Main.java

public static void setIValue(Context context, String strKey, int value) {

    SharedPreferences exam_info = context.getSharedPreferences("exam", 0);
    exam_info.edit().putInt(strKey, value).commit();
}