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

@SuppressLint("CommitPrefEdits")
public static void defaultState(Context context, boolean state) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    if (!prefs.contains("wifi_state"))
        prefs.edit().putBoolean("wifi_state", state).commit();
}

From source file:Main.java

public static void AppSetFirstRunFlag(Context context) {
    int versionNum = getPackageVersionNum(context);
    SharedPreferences settings = context.getSharedPreferences(PREFS_NAME, 0);
    SharedPreferences.Editor editor = settings.edit();
    editor.putBoolean(APP_IS_FIRST + versionNum, false);
    editor.commit();//from   w  w  w  . ja v  a  2  s  .c  om
}

From source file:Main.java

public static void saveLongSPR(String key, Long value, Context context) {
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
    SharedPreferences.Editor editor = preferences.edit();

    editor.putLong(key, value);/*from  w w w .ja  v  a 2  s .com*/

    editor.commit();

}

From source file:Main.java

public static void savePhone(Context context, String phone) {
    SharedPreferences preferences = context.getSharedPreferences(SETTINGS, Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = preferences.edit();
    editor.putString(PHONE, phone);// w  w  w . j ava2 s  .  co  m
    editor.apply();
}

From source file:Main.java

public static void setBlacklist(SharedPreferences prefs, String languageCode, String blacklist) {
    if (languageCode.equals("deu")) {
        prefs.edit().putString(KEY_CHARACTER_BLACKLIST_PAYMENT_SLIP, blacklist).commit();
    } else {/*w  w  w .j ava2s .  c o m*/
        throw new IllegalArgumentException();
    }
}

From source file:Main.java

public static void saveData(Context context, String key, String value) {
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
    SharedPreferences.Editor editor = sharedPreferences.edit();
    editor.putString(key, value);/*from w  w w.java  2s .  c o  m*/
    editor.apply();
}

From source file:Main.java

public static void setPosterStatus(Context context, boolean status) {
    SharedPreferences sp = context.getSharedPreferences("recommend_poster", Activity.MODE_PRIVATE);
    SharedPreferences.Editor tor = sp.edit();
    tor.putBoolean("poster_status", status);
    tor.commit();/*from  www .ja  v a  2 s.  c  om*/
}

From source file:Main.java

public static void saveFirstLogin(Context context, boolean IsFirst) {
    SharedPreferences preferences = context.getSharedPreferences("FirstLogin", Context.MODE_PRIVATE);
    SharedPreferences.Editor edit = preferences.edit();
    edit.putBoolean("Isfirst", IsFirst);
    edit.commit();/*w ww .  j a v a  2 s.co m*/
}

From source file:Main.java

/**
 * Forget the account name and authToken. With no account name the app will
 * prompt the user to select a new account. This method is mostly used for
 * testing purposes.//w ww .j  a va2s  .  c om
 * 
 * @param activity
 */
public static void resetAccountCredential(Activity activity) {
    Log.i(TAG, "Reset credentials");
    SharedPreferences settings = activity.getPreferences(Activity.MODE_PRIVATE);
    SharedPreferences.Editor editor2 = settings.edit();
    editor2.remove(PREF_AUTH_TOKEN);
    editor2.remove(PREF_ACCOUNT_NAME);
    editor2.commit();
}

From source file:Main.java

public static void setWhitelist(SharedPreferences prefs, String languageCode, String whitelist) {
    if (languageCode.equals("eng")) {
        prefs.edit().putString(KEY_CHARACTER_WHITELIST_ENGLISH, whitelist).commit();
    } else {//from w  w w  . ja  v  a2  s.co m
        throw new IllegalArgumentException();
    }
}