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 setDeclaretion(Context context, String key, String value) {
    if (null == context) {
        return;/*from   ww w  .ja  v  a  2  s . c  o  m*/
    }
    SharedPreferences spf = PreferenceManager.getDefaultSharedPreferences(context);
    SharedPreferences.Editor editor = spf.edit();
    editor.putString(key, value);
    editor.commit();
}

From source file:Main.java

static void saveCurrentAppKey(Context context, String appKey) {
    if (appKey != null) {
        SharedPreferences prefs = context.getSharedPreferences(AGE_PREFERENCES, Context.MODE_PRIVATE);
        Editor editor = prefs.edit();
        editor.putString(AGE_CURRENT_APP_KEY, appKey);
        editor.commit();//from  ww  w  .  j av  a  2s.c o  m
    }
}

From source file:Main.java

public static void remove(Context context, String key) {
    SharedPreferences sp = context.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = sp.edit();
    editor.remove(key);/*w  ww .  j  a v  a 2 s  .  c  om*/
    //        SharedPreferencesCompat.apply(editor);
    editor.commit();
}

From source file:Main.java

public static void deleteSet(SharedPreferences prefs, String setName) {
    final int size = prefs.getInt(setName + "_size", 0);
    Editor editor = prefs.edit();
    for (int i = 0; i < size; i++)
        editor.remove(setName + "_" + i);
    editor.remove(setName + "_size");
    editor.commit();//  w ww . j  av a2s.  c  o  m
}

From source file:Main.java

public static void setRecommendRightFlag(Context context, boolean flag) {
    if (context != null) {
        SharedPreferences settings = context.getSharedPreferences(RECOMMEND_RIGHT, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putBoolean(RECOMMEND_FIRST, flag);
        editor.commit();/*from w  w  w.  j a va  2  s.  c o m*/
    }
}

From source file:Main.java

public static void putSharedPref(Context context, String name, Object object) {
    SharedPreferences prefs = context.getSharedPreferences("TheMovieDb", Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = prefs.edit();
    editor.putString(name, object.toString());
    editor.commit();//  ww  w.ja v a  2 s  .co m
}

From source file:Main.java

public static void remove(Context context, String fileName, String k) {
    SharedPreferences preference = context.getSharedPreferences(fileName, Context.MODE_PRIVATE);
    Editor editor = preference.edit();
    editor.remove(k);/*from   w  ww  . ja va 2s.co  m*/
    editor.commit();
}

From source file:Main.java

public static void setPosterHelpStatus(Context context, boolean status) {
    SharedPreferences sp = context.getSharedPreferences("poster_help", Activity.MODE_PRIVATE);
    SharedPreferences.Editor tor = sp.edit();
    tor.putBoolean("poster_help", status);
    tor.commit();/*from   w w w. j av  a2s.  co  m*/
}

From source file:Main.java

public static void removePreferenceNoId(Context ctx, String param) {
    SharedPreferences settings = ctx.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = settings.edit();
    editor.remove(param);/*from  www . ja  v a  2s . c o m*/
    editor.commit();
}

From source file:Main.java

public static void setDayNightMode(Context context, int mode) {
    SharedPreferences sharedPreferences = getSharedPreferences(context);
    SharedPreferences.Editor sharedPreferencesEditor = sharedPreferences.edit();
    sharedPreferencesEditor.putInt("SUN_NIGHT_MODE", mode);
    sharedPreferencesEditor.apply();//from   w  w w . j av a 2s  .  c  o m
}