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 setRootEnabled(Context context, boolean isRoot) {
    SharedPreferences preferenceScreen = PreferenceManager.getDefaultSharedPreferences(context);
    preferenceScreen.edit().putBoolean("isRootEnabled", isRoot).apply();
}

From source file:Main.java

public static void putVersion(Context context, String version) {
    SharedPreferences preferences = context.getSharedPreferences(VERSION, Context.MODE_PRIVATE);
    preferences.edit().putString(VERSION_KEY, version).commit();
}

From source file:Main.java

public static void putSharedPreferencesFloat(Context context, String key, float val) {
    SharedPreferences preferences = context.getSharedPreferences(PREFS_NAME, 0);
    Editor edit = preferences.edit();
    edit.putFloat(key, val);
    edit.commit();/*  w  w  w  .  j a  va  2s.  co  m*/
}

From source file:Main.java

public static void putUserPic(Context context, String city) {
    SharedPreferences preferences = context.getSharedPreferences(USERPIC, Context.MODE_PRIVATE);
    preferences.edit().putString(CVALUE, city).commit();
}

From source file:Main.java

public static void putSharedPreferencesBoolean(Context context, String key, boolean val) {
    SharedPreferences preferences = context.getSharedPreferences(PREFS_NAME, 0);
    Editor edit = preferences.edit();
    edit.putBoolean(key, val);
    edit.commit();/* ww  w.j  ava  2  s .  c o  m*/
}

From source file:Main.java

public static void setLastUsedTrackID(Context context, String trackID) {
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
    sp.edit().putString("last_track_id", trackID).commit();
}

From source file:Main.java

public static void putIpPort(Context context, String ip) {
    SharedPreferences preferences = context.getSharedPreferences(IP_PORT, Context.MODE_PRIVATE);
    preferences.edit().putString(CVALUE, ip).commit();
}

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)
            .commit();//from w w w  . j  ava2 s.co m
}

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)
            .commit();//from  w ww.java 2  s  .  co m
}

From source file:Main.java

public static void putSharedPreferencesInt(Context context, String key, int value) {
    SharedPreferences preferences = context.getSharedPreferences(PREFS_NAME, 0);
    Editor edit = preferences.edit();
    edit.putInt(key, value);/* w  w  w.  j  a  va  2s .c om*/
    edit.commit();
}