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

/**
 * Set a new interval for the data sync time.
 *
 * @param context  Context to be used to edit the {@link android.content.SharedPreferences}.
 * @param newValue New value that will be set.
 *//* ww w .ja  v a  2 s .c  om*/
public static void setCurSyncInterval(final Context context, long newValue) {
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
    sp.edit().putLong(PREF_CUR_SYNC_INTERVAL, newValue).apply();
}

From source file:Main.java

/**
 * Mark the// ww  w  .j ava  2  s  . com
 * {@code com.google.samples.apps.iosched.welcome.WelcomeActivity.displayDogfoodWarningDialog() Dogfood Build Warning}
 * shown to user.
 *
 * @param context Context to be used to edit the {@link android.content.SharedPreferences}.
 */
public static void markDebugWarningShown(final Context context) {
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
    sp.edit().putBoolean(PREF_DEBUG_BUILD_WARNING_SHOWN, true).apply();
}

From source file:Main.java

/**
 * Mark that the app has finished loading the {@code R.raw.bootstrap_data bootstrap data}.
 *
 * @param context Context to be used to edit the {@link android.content.SharedPreferences}.
 *///  ww w.  ja  v a2  s  . c o  m
public static void markDataBootstrapDone(final Context context) {
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
    sp.edit().putBoolean(PREF_DATA_BOOTSTRAP_DONE, true).apply();
}

From source file:Main.java

public static void setPlusProfileId(final Context context, final String accountName, final String profileId) {
    SharedPreferences sp = getSharedPreferences(context);
    sp.edit().putString(makeAccountSpecificPrefKey(accountName, PREFIX_PREF_PLUS_PROFILE_ID), profileId)
            .apply();/*  w w w.  j ava 2  s  .c  o  m*/
}

From source file:Main.java

public static void clear() {
    SharedPreferences preferences = getPrivateSharedPreference();
    SharedPreferences.Editor editor = preferences.edit();
    editor.clear();/*from w  w w. j a v  a 2 s  .  c om*/
    editor.commit();
}

From source file:Main.java

public static void saveBooleanPreferences(String key, boolean value, Context ctx) {
    SharedPreferences sp = ctx.getSharedPreferences(sharedPrefsFile, Context.MODE_PRIVATE);
    Editor edit = sp.edit();
    edit.putBoolean(key, value);//from w  w w .  ja  v a 2  s  .c om
    edit.commit();
}

From source file:Main.java

public static void setPlusCoverUrl(final Context context, final String accountName, String coverPhotoUrl) {
    SharedPreferences sp = getSharedPreferences(context);
    sp.edit().putString(makeAccountSpecificPrefKey(accountName, PREFIX_PREF_PLUS_COVER_URL), coverPhotoUrl)
            .apply();// w ww  .j  a v a 2s  .c  o  m
}

From source file:Main.java

public static void deleteLogin(Context context) {
    SharedPreferences preferences = context.getSharedPreferences(USER_INFO, Context.MODE_PRIVATE);
    preferences.edit().clear().commit();
    SharedPreferences preferences1 = context.getSharedPreferences(USER_INFO_OTHER, Context.MODE_PRIVATE);
    preferences1.edit().clear().commit();
    SharedPreferences preferences2 = context.getSharedPreferences(QQ, Context.MODE_PRIVATE);
    preferences.edit().clear().commit();
}

From source file:Main.java

public static void writeWLPref(Context context, String prefName, String PrefValue) {
    SharedPreferences prefs = context.getSharedPreferences("WLPrefs", 0);
    SharedPreferences.Editor editor = prefs.edit();
    editor.putString(prefName, PrefValue);
    editor.commit();//  ww  w  .  j av a2s.  com
}

From source file:Main.java

public static void clearWLPref(Context context) {
    SharedPreferences prefs = context.getSharedPreferences("WLPrefs", 0);
    SharedPreferences.Editor editor = prefs.edit();
    editor.clear();/*from ww w  .j a v a2 s  .  com*/
    editor.commit();
}