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

/**
 * save long value to preference memory//from www.  j  a  v  a2  s  .  c om
 */
public static void saveLong(Context context, String key, long value) {
    if (context == null)
        return;

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

From source file:Main.java

public static void putSharedPreferencesString(Context context, String key, String val) {
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
    SharedPreferences.Editor edit = preferences.edit();
    edit.putString(key, val);
    edit.commit();/*from  w  ww  .j  ava 2  s  .  c  o m*/
}

From source file:Main.java

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

From source file:Main.java

public static void putSharedPreferencesFloat(Context context, String key, float val) {
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
    SharedPreferences.Editor edit = preferences.edit();
    edit.putFloat(key, val);
    edit.commit();/*from   ww  w.j a v a 2  s  .c  om*/
}

From source file:Main.java

public static void saveKeyValueData(String key, String value, Activity ctx) {
    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(ctx);
    SharedPreferences.Editor editor = sharedPref.edit();
    editor.putString(key, value);/*  w w w  .  jav  a  2s .  c  om*/
    editor.commit();
}

From source file:Main.java

public static void clear(Context context) {
    SharedPreferences sp = context.getSharedPreferences(FILENAME, Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = sp.edit();
    editor.clear();// w  w w  .  j av  a2 s  .c o  m
    editor.apply();
}

From source file:Main.java

public static void putSharedPreferencesBoolean(Context context, String key, boolean val) {
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
    SharedPreferences.Editor edit = preferences.edit();
    edit.putBoolean(key, val);
    edit.commit();//from  w w  w . ja v  a2s.  c  o  m
}

From source file:Main.java

public static void putSharedPreferencesLong(Context context, String key, long val) {
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
    SharedPreferences.Editor edit = preferences.edit();
    edit.putLong(key, val);
    edit.commit();/*from  www .j a v  a  2  s . com*/
}

From source file:Main.java

public static void putSharedPreferencesFloat(Context context, String key, float val) {
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
    SharedPreferences.Editor edit = preferences.edit();
    edit.putFloat(key, val);
    edit.apply();/*from  ww w  . ja  v  a  2 s. c o  m*/
}

From source file:Main.java

public static void clear(Context context) {
    SharedPreferences sp = context.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = sp.edit();
    editor.clear().commit();/*w  w w  . j  av a  2 s  . co  m*/
}