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 void putString(Context context, String key, String value) {
    SharedPreferences sp = context.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
    sp.edit().putString(key, value).commit();
}

From source file:Main.java

public static void setActiveAccountAuthorized(final Context context, String accountName,
        final Boolean authorized) {
    SharedPreferences sp = getSharedPreferences(context);
    sp.edit().putBoolean(makeAccountSpecificPrefKey(accountName, PREFIX_PREF_AUTHORIZED), authorized).apply();
}

From source file:Main.java

public static void setActiveAccountID(final Context context, final String accountName, final Integer userID) {
    SharedPreferences sp = getSharedPreferences(context);
    sp.edit().putString(makeAccountSpecificPrefKey(accountName, PREFIX_PREF_USER_ID), userID.toString())
            .apply();// w  ww  . ja  v a  2 s. c  om
}

From source file:Main.java

public static void removeValue(Context context, String name) {
    SharedPreferences pref = getPref(context, DEF_PREF_NAME);
    Editor editor = pref.edit();
    editor.remove(name);//from   w  w  w.j  a va2  s.  c  o m
    editor.commit();
}

From source file:Main.java

public static void setActiveAccountFullName(final Context context, final String accountName,
        final String fullName) {
    SharedPreferences sp = getSharedPreferences(context);
    sp.edit().putString(makeAccountSpecificPrefKey(accountName, PREFIX_PREF_FULL_NAME), fullName).apply();
}

From source file:Main.java

public static void clearAll(Context context) {
    SharedPreferences pref = getPref(context, DEF_PREF_NAME);
    Editor editor = pref.edit();
    editor.clear();// www . ja  v  a 2  s.  c  o  m
    editor.commit();
}

From source file:Main.java

public static void setActiveAccountTeamName(final Context context, final String accountName,
        final String teamName) {
    SharedPreferences sp = getSharedPreferences(context);
    sp.edit().putString(makeAccountSpecificPrefKey(accountName, PREFIX_PREF_TEAM_NAME), teamName).apply();
}

From source file:Main.java

public static void setIntValue(Context context, String name, int value) {
    SharedPreferences pref = getPref(context, DEF_PREF_NAME);
    Editor editor = pref.edit();
    editor.putInt(name, value);//  ww w . j a  va 2s. c o m
    editor.commit();
}

From source file:Main.java

public static void putBoolean(Context context, String key, boolean value) {
    SharedPreferences sp = context.getSharedPreferences("budejie", Context.MODE_PRIVATE);
    sp.edit().putBoolean(key, value).commit();
}

From source file:Main.java

public static void savePreference(Context context, String key, String value) {
    SharedPreferences sp = context.getSharedPreferences("config", Context.MODE_PRIVATE);
    sp.edit().putString(key, value).apply();
}