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 setFbDetails(Context context, String fb_id, String fb_name) {
    SharedPreferences fbInfo = context.getSharedPreferences(FB_VARIABLES, 0);
    SharedPreferences.Editor editor = fbInfo.edit();
    editor.putString(FB_ID, fb_id);//from  w ww .  j  a va 2s .  c  o  m
    editor.putString(FB_NAME, fb_name);
    editor.putString(IS_FIRST_TIME, "yes");
    editor.commit();
}

From source file:Main.java

public static void updateLastUsedTimestamp(Context context) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    SharedPreferences.Editor edit = prefs.edit();
    edit.putLong(LASTUSED_PARAM, System.currentTimeMillis());
    edit.commit();//from  ww  w  .j av a 2 s.  c o m
}

From source file:Main.java

public static void setLoginState(Context context, boolean isLogin) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    SharedPreferences.Editor editor = prefs.edit();
    editor.putBoolean(STATE_LOGIN, isLogin);
    editor.commit();//  w ww  .j a  v  a  2  s .c  o m
}

From source file:Main.java

public static void SpIntertBoolean(Context c, String key, Boolean value) {
    SharedPreferences sp = c.getSharedPreferences("XGram", Context.MODE_WORLD_READABLE);
    SharedPreferences.Editor editor = sp.edit();
    editor.putBoolean(key, value);//  w w  w. j a v a2 s .  c om
    editor.apply();
}

From source file:Main.java

public static void putFontSize(Context context, String key, int state) {
    SharedPreferences prefe = context.getSharedPreferences(PREFERNCE_FILE_NAME, Context.MODE_PRIVATE);
    Editor editor = prefe.edit();
    editor.putInt(key, state);//from   w w  w  .  ja v  a 2s  .  com
    editor.commit();
}

From source file:Main.java

public static void putLong(Context context, String title, long content) {
    SharedPreferences sp = context.getSharedPreferences(FILENAME, Context.MODE_PRIVATE);
    SharedPreferences.Editor edit = sp.edit();
    edit.putLong(title, content);// w  w  w .j av  a  2  s  . com
    edit.commit();
}

From source file:Main.java

public static void putBoolean(Context context, String title, boolean content) {
    SharedPreferences sp = context.getSharedPreferences(FILENAME, Context.MODE_PRIVATE);
    SharedPreferences.Editor edit = sp.edit();
    edit.putBoolean(title, content);// w  w  w.  j  av a2  s .com
    edit.commit();
}

From source file:Main.java

public static void setUserId(Context context, String userId) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    SharedPreferences.Editor editor = prefs.edit();
    editor.putString(USER_ID, userId);/*from w  w  w . ja v a 2 s . c om*/
    editor.commit();
}

From source file:Main.java

public static void putInt(Context context, String title, int content) {
    SharedPreferences sp = context.getSharedPreferences(FILENAME, Context.MODE_PRIVATE);
    SharedPreferences.Editor edit = sp.edit();
    edit.putInt(title, content);//www.ja  v a2s . c o  m
    edit.commit();
}

From source file:Main.java

public static void putString(Context context, String title, String content) {
    SharedPreferences sp = context.getSharedPreferences(FILENAME, Context.MODE_PRIVATE);
    SharedPreferences.Editor edit = sp.edit();
    edit.putString(title, content);//from w  ww . j a  va 2s  . c o m
    edit.commit();
}