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 resetPref(Context context) {
    SharedPreferences pref = context.getSharedPreferences("TVGuide", Context.MODE_PRIVATE);
    Editor editor = pref.edit();
    editor.clear();//  ww  w.  ja va 2s .co m
    editor.apply();
}

From source file:Main.java

/**
 * Clears all the persisted responses./*from   w  w w .j  av  a 2 s . com*/
 */
public static void clearResponses(Context context) {
    SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
    pref.edit().remove(PREF_SESSION_ID).apply();
    for (String name : PREF_RESPONSES) {
        pref.edit().remove(name).apply();
    }
}

From source file:Main.java

public static boolean saveList(SharedPreferences prefs, List<String> list, String listName) {
    SharedPreferences.Editor editor = prefs.edit();
    editor.putInt(listName + "_size", list.size());
    int i = 0;/*from  w  ww  . j a v a 2s .  c  o  m*/
    for (String s : list) {
        editor.putString(listName + "_" + i, s);
        ++i;
    }
    return editor.commit();
}

From source file:Main.java

public static void setWiFiConfigStatus(final Context context, final String status) {
    if (!WIFI_CONFIG_DONE.equals(status) && !WIFI_CONFIG_REQUESTED.equals(status))
        throw new IllegalArgumentException("Invalid WiFi Config status: " + status);
    final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
    sp.edit().putString(PREF_WIFI_AP_CONFIG, status).commit();
}

From source file:Main.java

public static void setAuthToken(final Context context, final String accountName, final String authToken) {
    SharedPreferences sp = getSharedPreferences(context);
    sp.edit().putString(makeAccountSpecificPrefKey(accountName, PREFIX_PREF_AUTH_TOKEN), authToken).apply();
}

From source file:Main.java

public static void setStringSharedPreferences(Context context, String name, String key, String value) {
    SharedPreferences preferences = context.getSharedPreferences(name, 0);
    SharedPreferences.Editor editor = preferences.edit();
    editor.putString(key, value == null ? "" : value);
    editor.commit();/*from ww  w.  j  a  va  2s . co  m*/
}

From source file:Main.java

public static void setWiFiConfigStatus(final Context context, final String status) {
    if (!WIFI_CONFIG_DONE.equals(status) && !WIFI_CONFIG_REQUESTED.equals(status))
        throw new IllegalArgumentException("Invalid WiFi Config status: " + status);
    final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
    sp.edit().putString(PREF_WIFI_AP_CONFIG, status).apply();
}

From source file:Main.java

public static void setUserFromPrefrence(Context context, String nickname) {
    SharedPreferences sh = context.getSharedPreferences("xmeet_prefrence", Context.MODE_PRIVATE);
    Editor dt = sh.edit();
    dt.putString("nickname", nickname);
    dt.commit();/*from   ww  w.j  a v  a  2s  .co  m*/
}

From source file:Main.java

public static void createPreferences(Context context) {
    SharedPreferences pref = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
    Editor editor = pref.edit();
    editor.commit();/*from ww  w.  j  a  v  a  2  s .co m*/
    System.out.println("Preferences created");
}

From source file:Main.java

public static void setIntegerSharedPreferences(Context context, String name, String key, int value) {
    SharedPreferences preferences = context.getSharedPreferences(name, 0);
    SharedPreferences.Editor editor = preferences.edit();
    editor.putInt(key, value);// w  w w .  j av a 2s. c o  m
    editor.commit();
}