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 setLong(Context context, final String key, final long value) {
    final SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
    settings.edit().putLong(key, value).commit();
}

From source file:Main.java

public static void setPrefInt(Context context, final String key, final int value) {
    final SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
    settings.edit().putInt(key, value).commit();
}

From source file:Main.java

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

From source file:Main.java

public static void clearUser(Context context) {
    SharedPreferences preferences = context.getSharedPreferences("USER", Context.MODE_PRIVATE);
    preferences.edit().clear().commit();
}

From source file:Main.java

/**
 *
 * @param ctx/*from  w  w w  .j a v a2 s. c om*/
 * @param key
 * @return
 */
public static boolean removeGlobalSetting(Context ctx, String key) {
    SharedPreferences setting = ctx.getSharedPreferences(ctx.getPackageName(), 0);
    return setting.edit().remove(key).commit();
}

From source file:Main.java

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

From source file:Main.java

public static void setIsInitDb(Context context, boolean b) {
    final SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
    settings.edit().putBoolean(EXTRA_ISINITDB, b).commit();
}

From source file:Main.java

public static void saveString(Context context, String key, String values) {
    SharedPreferences preferences = context.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
    preferences.edit().putString(key, values).commit();
}

From source file:Main.java

public static void clearKeys(Context context) {
    DropboxSecret = "";
    SharedPreferences prefs = context.getSharedPreferences(DROPBOX_ACCOUNT_PREFS_NAME, 0);
    prefs.edit().remove(ACCESS_SECRET_NAME).commit();
}

From source file:Main.java

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