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 setPreference(Context context, String preference, int value) {
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
    SharedPreferences.Editor editor = settings.edit();
    editor.putInt(preference, value);/* w w w  .ja va2  s.  c o  m*/
    editor.apply();
}

From source file:Main.java

public static void storeToPreference(Context context, String filename, String key, String value) {
    SharedPreferences preferences = context.getSharedPreferences(filename, context.MODE_PRIVATE);
    SharedPreferences.Editor editor = preferences.edit();
    editor.putString(key, value);//ww w .j a va2 s.c o m
    editor.commit();
}

From source file:Main.java

private static void persist(Context context, String language) {
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
    SharedPreferences.Editor editor = preferences.edit();

    editor.putString(SELECTED_LANGUAGE, language);
    editor.apply();/*  w  w w  .  j  a v  a2 s  . c  om*/
}

From source file:Main.java

public static String fetchObjectSharePref(Context context, String key) {
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
    SharedPreferences.Editor prefsEditor = preferences.edit();
    return preferences.getString(key, "");
}

From source file:Main.java

public static Boolean fetchBoolianSharePref(Context context, String key) {
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
    SharedPreferences.Editor prefsEditor = preferences.edit();
    return preferences.getBoolean(key, false);
}

From source file:Main.java

public static long fetchLongSharePref(Context context, String key) {
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
    SharedPreferences.Editor prefsEditor = preferences.edit();
    return preferences.getLong(key, -1);
}

From source file:Main.java

public static void saveToPref(Context context, String key, String val) {
    SharedPreferences preferences = context.getSharedPreferences(FILENAME, context.MODE_PRIVATE);
    SharedPreferences.Editor editor = preferences.edit();
    editor.putString(key, val);
    editor.commit();//from w  ww  .java  2s  . c o m
}

From source file:Main.java

public static boolean writeRecords(int gameId, String key, String value) {
    boolean result = false;
    try {//ww w. j a  v  a 2s  .  c o  m
        SharedPreferences mPerferences = PreferenceManager.getDefaultSharedPreferences(mContext);
        Editor editor = mPerferences.edit();
        editor.putString(key, value);
        editor.commit();
        result = true;
    } catch (Exception e) {
        result = false;
    }
    return result;
}

From source file:Main.java

public static void setWhitelist(SharedPreferences prefs, String languageCode, String whitelist) {
    if (languageCode.equals("deu")) {
        prefs.edit().putString(KEY_CHARACTER_WHITELIST_PAYMENT_SLIP, whitelist).commit();
    } else {//  w w  w.ja  v a  2 s  . c  om
        throw new IllegalArgumentException();
    }
}

From source file:Main.java

/**
 * Utility method to remove the flag when the cloud session has been
 * created.// w  ww.  j  av a 2s .  co  m
 * 
 * @param context
 */
public static void removeLastCloudLoadingTime(Context context) {
    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context);
    Editor editor = sharedPref.edit();
    editor.remove(KEY_CLOUD_LOADING_TIME);
    editor.commit();
}