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

/**
 * put boolean preferences//from ww w.  j  a v a2 s. com
 * 
 * @param context
 * @param key The name of the preference to modify
 * @param value The new value for the preference
 * @return True if the new values were successfully written to persistent storage.
 */
public static boolean putBoolean(Context context, String key, boolean value) {
    SharedPreferences settings = getDefaultPreferences(context);
    SharedPreferences.Editor editor = settings.edit();
    editor.putBoolean(key, value);
    return editor.commit();
}

From source file:Main.java

/**
 * put float preferences/*  ww w.  ja  v a2 s.c  o m*/
 * 
 * @param context
 * @param key The name of the preference to modify
 * @param value The new value for the preference
 * @return True if the new values were successfully written to persistent storage.
 */
public static boolean putFloat(Context context, String key, float value) {
    SharedPreferences settings = getDefaultPreferences(context);
    SharedPreferences.Editor editor = settings.edit();
    editor.putFloat(key, value);
    return editor.commit();
}

From source file:Main.java

public static void saveAutoRefreshToPreference(Context c, boolean autoRefresh) {
    SharedPreferences preferences = c.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
    Editor editor = preferences.edit();
    editor.putBoolean(PREF_AUTO_REFRESH, autoRefresh);
    editor.apply();/* www .j av a 2s  .c o  m*/
}

From source file:Main.java

public static void writeConfig(Context context, String key, String val) {
    SharedPreferences share = context.getSharedPreferences("perference", Context.MODE_PRIVATE);
    Editor editor = share.edit();
    editor.putString(key, val);
    editor.commit();//from   w  w  w .j a  v  a 2 s  .com
}

From source file:Main.java

public static void setStringPref(Context context, String name, String value) {
    SharedPreferences prefs = context.getSharedPreferences(APPLICATION_NAME, Context.MODE_PRIVATE);
    Editor ed = prefs.edit();
    ed.putString(name, value);/*  ww w  .  j  a va  2 s. c om*/
    ed.commit();
}

From source file:Main.java

public static void saveLongToSharePrefs(Context context, String fileName, String key, long value) {
    SharedPreferences preferences = context.getSharedPreferences(fileName, Context.MODE_PRIVATE);
    Editor editor = preferences.edit();
    editor.putLong(key, value);/*w  w  w. ja v a2  s  .  com*/
    editor.commit();
}

From source file:Main.java

public static void saveIntToSharePrefs(Context context, String fileName, String key, int value) {
    SharedPreferences preferences = context.getSharedPreferences(fileName, Context.MODE_PRIVATE);
    Editor editor = preferences.edit();
    editor.putInt(key, value);/*w  w  w .ja v  a2 s.  c  o m*/
    editor.commit();
}

From source file:Main.java

public static void setLongPref(Context context, String name, long value) {
    SharedPreferences prefs = context.getSharedPreferences(APPLICATION_NAME, Context.MODE_PRIVATE);
    Editor ed = prefs.edit();
    ed.putLong(name, value);/*from  w  w  w. ja v a  2 s.c  om*/
    ed.commit();
}

From source file:Main.java

public static void clear(Context context) {
    SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
    settings.edit().clear().commit();
}

From source file:Main.java

public static void setIntPref(Context context, String name, int value) {
    SharedPreferences prefs = context.getSharedPreferences(APPLICATION_NAME, Context.MODE_PRIVATE);
    Editor ed = prefs.edit();
    ed.putInt(name, value);/*from  ww w.jav  a2s.c  o  m*/
    ed.commit();
}