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 setLogText(Context context, String text) {
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
    Editor editor = sp.edit();
    editor.putString("log_text", text);
    editor.commit();/*from  w  ww  .  j  av a  2 s  .  c  om*/
}

From source file:Main.java

public static boolean putBoolean(Context context, String tag, boolean value) {
    SharedPreferences prefs = getSharedPreference(context);
    SharedPreferences.Editor editor = prefs.edit();
    editor.putBoolean(tag, value);/*  w w  w. j ava 2 s  .c  o m*/
    return editor.commit();
}

From source file:Main.java

public static void clear(Context context) {
    SharedPreferences pref = context.getSharedPreferences(context.getPackageName() + "_preferences", 0);
    pref.edit().clear().commit();
}

From source file:Main.java

public static boolean saveUrl(Context context, String key, String value) {
    SharedPreferences preferences = getSharedPreference(SF_URLS, context);
    Editor editor = preferences.edit();
    editor.putString(key, value);/*w ww .  j  av a  2  s. c  o  m*/
    return editor.commit();
}

From source file:Main.java

public static void setFirstFullScreen(Context ctt, boolean first) {
    if (ctt != null) {
        SharedPreferences sp = ctt.getSharedPreferences(PREFERENCES_FIRST_IN, Context.MODE_PRIVATE);
        sp.edit().putBoolean(KEY_FIRST_FULL_SCREEN, first).commit();
    }//ww  w. j  a  va 2 s.  c o  m
}

From source file:Main.java

public static void setMapHintVisibility(Context context, boolean visible) {
    SharedPreferences sharedPref = context.getSharedPreferences(KEY_SHOW_MAP_HINT, Context.MODE_PRIVATE);
    sharedPref.edit().putBoolean(KEY_SHOW_MAP_HINT, visible).apply();
}

From source file:Main.java

public static void saveLongValue(Context context, String key, Long value) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    Editor editor = prefs.edit();
    editor.putLong(key, value);//from   w w w . j a v a2s.co  m
    editor.commit();
}

From source file:Main.java

public static void setCurrentUserImageProfileUri(Context context, String uri) {
    SharedPreferences prefs = context.getSharedPreferences(SHARED_PREFERENCES_FILE, Context.MODE_PRIVATE);
    prefs.edit().putString("userImageUri", uri).apply();
}

From source file:Main.java

/**
 * Stores the given sender ID.//from   ww  w .  j ava2s .  co m
 *  
 * @param context The application context.
 * @param id The sender ID to store.
 * @return True if successful, false otherwise.
 */
public static boolean setSenderId(Context context, String id) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    return prefs.edit().putString(PREFS_KEY_SENDER_ID, id).commit();
}

From source file:Main.java

public static void disable(final SharedPreferences pref, final String id) {
    final SharedPreferences.Editor editor = pref.edit();
    editor.putBoolean(id, false);/*w  w  w .  j  a va  2 s  .  c  om*/
    editor.apply();
}