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(key, Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = sp.edit();
    editor.putString(key, value);/* ww  w .  ja v  a 2 s.  c  o m*/
    editor.apply();
}

From source file:Main.java

public static void setRun(Context context) {
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
    SharedPreferences.Editor editor = sp.edit();
    editor.putBoolean("firstRun", true);
    editor.commit();//  w w w .  j  ava  2s.  c  om
}

From source file:Main.java

public static void setStr(Context mContext, String name, String key, String value) {
    SharedPreferences sharedPreferences = mContext.getSharedPreferences(name, Context.MODE_PRIVATE);
    Editor editor = sharedPreferences.edit();
    editor.putString(key, value);//w  w  w  .j a va 2  s  . c o  m
    editor.commit();
}

From source file:Main.java

public static void appendSettingString(final SharedPreferences sp, final String key, final String append) {
    String oldValue = sp.getString(key, "");
    sp.edit().putString(key, oldValue + append).commit();
}

From source file:Main.java

public static void setInt(Context mContext, String name, String key, int value) {
    SharedPreferences sharedPreferences = mContext.getSharedPreferences(name, Context.MODE_PRIVATE);
    Editor editor = sharedPreferences.edit();
    editor.putInt(key, value);//w w  w.ja  va 2s.co  m
    editor.commit();
}

From source file:Main.java

public static void putLong(Context context, String key, long value) {
    SharedPreferences sp = context.getSharedPreferences(key, Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = sp.edit();
    editor.putLong(key, value);//  w w  w .  j  a  va  2s.c o  m
    editor.apply();
}

From source file:Main.java

/**
 * save string to preference memory/*from   w ww. j a  va 2 s  .c om*/
 */
public static void saveString(Context context, String key, String value) {
    if (context == null)
        return;

    SharedPreferences pref = context.getSharedPreferences(PREF_NAME, 0);
    SharedPreferences.Editor editor = pref.edit();
    editor.putString(key, value);
    editor.commit();
}

From source file:Main.java

public static void removeString(Context mContext, String name, String key) {
    SharedPreferences sharedPreferences = mContext.getSharedPreferences(name, Context.MODE_PRIVATE);
    Editor editor = sharedPreferences.edit();
    editor.remove(key);/*w w w.j a va  2  s .c om*/
    editor.commit();
}

From source file:Main.java

public static void putBoolean(Context context, String key, boolean value) {
    SharedPreferences sp = context.getSharedPreferences(key, Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = sp.edit();
    editor.putBoolean(key, value);//  w  ww .j  a  v  a2 s . c  o  m
    editor.apply();
}

From source file:Main.java

public static void setLong(Context mContext, String name, String key, long value) {
    SharedPreferences sharedPreferences = mContext.getSharedPreferences(name, Context.MODE_PRIVATE);
    Editor editor = sharedPreferences.edit();
    editor.putLong(key, value);/*  ww  w  . j av a2s .  c o  m*/
    editor.commit();
}