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 putInt(Context context, String key, int value) {
    SharedPreferences sp = context.getSharedPreferences(key, Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = sp.edit();
    editor.putInt(key, value);//from  w  w w .j  a  v  a 2 s .c o m
    editor.apply();
}

From source file:Main.java

/**
 * save int value to preference memory/*  w  w w .j av  a  2 s  . c om*/
 */
public static void saveInt(Context context, String key, int value) {
    if (context == null)
        return;

    SharedPreferences pref = context.getSharedPreferences(PREF_NAME, 0);
    SharedPreferences.Editor editor = pref.edit();
    editor.putInt(key, value);
    editor.commit();
}

From source file:Main.java

/**
 * save boolean value to preference memory
 *///from  www.ja  v  a2  s  .co m
public static void saveBoolean(Context context, String key, boolean value) {
    if (context == null)
        return;

    SharedPreferences pref = context.getSharedPreferences(PREF_NAME, 0);
    SharedPreferences.Editor editor = pref.edit();
    editor.putBoolean(key, value);
    editor.commit();
}

From source file:Main.java

/********************* set shared preferences **************************/
public static void SetPreferences(Context con, String key, String value) {
    // save the data
    SharedPreferences preferences = con.getSharedPreferences("prefs_login", 0);
    SharedPreferences.Editor editor = preferences.edit();
    editor.putString(key, value);/*from   w  w  w.  jav  a  2 s . co  m*/
    editor.commit();
}

From source file:Main.java

public static void finishUsersFirstNoteCreate(String username, Context context) {
    SharedPreferences sharedPreferences = context.getSharedPreferences(SHARED_PREFERENCES_FILENAME, 0);
    sharedPreferences.edit().putBoolean(username + "_first_notecreate_flag", false).commit();
}

From source file:Main.java

public static void save(String key, String val) {
    SharedPreferences preferences = getPrivateSharedPreference();
    SharedPreferences.Editor editor = preferences.edit();
    editor.putString(key, val);
    editor.commit();//from w  w w .jav a2s  .c  om
}

From source file:Main.java

public static void finishUsersFirstLogin(String username, Context context) {
    SharedPreferences sharedPreferences = context.getSharedPreferences(SHARED_PREFERENCES_FILENAME, 0);
    sharedPreferences.edit().putBoolean(username + "_first_login_flag", false).commit();
}

From source file:Main.java

public static void finishUsersFirstMarkerClick(String username, Context context) {
    SharedPreferences sharedPreferences = context.getSharedPreferences(SHARED_PREFERENCES_FILENAME, 0);
    sharedPreferences.edit().putBoolean(username + "_first_markerclick_flag", false).commit();
}

From source file:Main.java

public static void clearLoginInfo(Context context) {
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
    SharedPreferences.Editor editor = sp.edit();
    editor.remove("account");
    editor.remove("password");
    editor.commit();//from  w  w w .ja v a2s. c om
}

From source file:Main.java

public static void setStringPref(Context context, String key, String s) {
    SharedPreferences sharedPref = context.getSharedPreferences(THEME_PREFS, 0);
    SharedPreferences.Editor e = sharedPref.edit();
    e.putString(key, s);/* w ww.ja  va 2 s.com*/
    e.commit();
}