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 putSharedPreferencesLong(Context context, String key, long val) {
    SharedPreferences preferences = context.getSharedPreferences(PREFS_NAME, 0);
    Editor edit = preferences.edit();
    edit.putLong(key, val);
    edit.commit();/*from  w w w  .j  a  v a  2  s  .c o m*/
}

From source file:Main.java

public static void markDismissedIOExtendedCard(final Context context) {
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
    sp.edit().putBoolean(PREF_DISMISSED_IO_EXTENDED_CARD, true).commit();
}

From source file:Main.java

public static void setCurSyncInterval(final Context context, long interval) {
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
    sp.edit().putLong(PREF_CUR_SYNC_INTERVAL, interval).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();
}

From source file:Main.java

public static void markDeclinedWifiSetup(final Context context) {
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
    sp.edit().putBoolean(PREF_DECLINED_WIFI_SETUP, true).commit();
}

From source file:Main.java

public static void markTosAccepted(final Context context) {
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
    sp.edit().putBoolean(PREF_TOS_ACCEPTED, true).commit();
}

From source file:Main.java

public static void markAnsweredLocalOrRemote(final Context context) {
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
    sp.edit().putBoolean(PREF_ANSWERED_LOCAL_OR_REMOTE, true).commit();
}

From source file:Main.java

public static void setBleStatus(final Context context, boolean status) {
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
    sp.edit().putBoolean(PREF_BLE_ENABLED, status).commit();
}

From source file:Main.java

public static boolean saveSetting(Context c, String key, String value) {
    SharedPreferences shared = PreferenceManager.getDefaultSharedPreferences(c);

    Editor e = shared.edit();

    e.putString(key, value);//from w  w  w .jav a  2  s .  c  om
    return e.commit();
}

From source file:Main.java

public static void putValueToSP(Context context, String key, Object obj) {
    SharedPreferences sp = getSharedPreferences(context);
    Editor editor = sp.edit();
    if (obj instanceof String) {
        editor.putString(key, (String) obj);
    } else if (obj instanceof Integer) {
        editor.putInt(key, (Integer) obj);
    } else if (obj instanceof Boolean) {
        editor.putBoolean(key, (Boolean) obj);
    } else if (obj instanceof Float) {
        editor.putFloat(key, (Float) obj);
    } else if (obj instanceof Long) {
        editor.putLong(key, (Long) obj);
    }//from  ww  w . j  a  v  a 2 s.  com
    editor.commit();
}