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 values) {
    SharedPreferences sp = context.getSharedPreferences("liu", Context.MODE_PRIVATE);
    sp.edit().putString(key, values).commit();

}

From source file:Main.java

public static void setBoolean(Context ctx, String key, boolean value) {
    SharedPreferences spf = ctx.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
    spf.edit().putBoolean(key, value).commit();
}

From source file:Main.java

public static void markWelcomeDone(final Context context) {
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
    sp.edit().putBoolean(PREF_WELCOME_DONE, true).apply();
}

From source file:Main.java

public static void setFloat(Context ctx, String key, Float value) {
    SharedPreferences sp = ctx.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
    sp.edit().clear();
    sp.edit().putFloat(key, value).commit();
}

From source file:Main.java

public static void setActiveAccountTeamID(final Context context, final String accountName,
        final Integer teamID) {
    SharedPreferences sp = getSharedPreferences(context);
    sp.edit().putInt(makeAccountSpecificPrefKey(accountName, PREFIX_PREF_TEAM_ID), teamID).apply();
}

From source file:Main.java

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

From source file:Main.java

public static void setActiveAccountImgUrl(final Context context, final String accountName,
        final String imageUrl) {
    SharedPreferences sp = getSharedPreferences(context);
    sp.edit().putString(makeAccountSpecificPrefKey(accountName, PREFIX_PREF_IMAGE_URL), imageUrl).apply();
}

From source file:Main.java

public static void setLongValue(Context context, String name, long value) {
    SharedPreferences pref = getPref(context, DEF_PREF_NAME);
    Editor editor = pref.edit();
    editor.putLong(name, value);/*from   www.  j ava 2  s  .  c om*/
    editor.commit();
}

From source file:Main.java

public static void saveWIFIOnly(Context context, boolean isChecked) {
    SharedPreferences sp = context.getSharedPreferences("setting", Context.MODE_PRIVATE);
    sp.edit().putBoolean("isWIFIOnly", isChecked).commit();
}

From source file:Main.java

public static void setString(Context ctx, String key, String value) {
    SharedPreferences sp = ctx.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
    sp.edit().clear();
    sp.edit().putString(key, value).commit();
}