Example usage for android.content Context getSharedPreferences

List of usage examples for android.content Context getSharedPreferences

Introduction

In this page you can find the example usage for android.content Context getSharedPreferences.

Prototype

public abstract SharedPreferences getSharedPreferences(File file, @PreferencesMode int mode);

Source Link

Document

Retrieve and hold the contents of the preferences file, returning a SharedPreferences through which you can retrieve and modify its values.

Usage

From source file:Main.java

public static void putString(Context context, String key, String value) {
    SharedPreferences sp = context.getSharedPreferences("superlol", Context.MODE_PRIVATE);
    sp.edit().putString(key, value).commit();

}

From source file:Main.java

public static void putString(Context context, String key, String values) {
    SharedPreferences sp = context.getSharedPreferences("kieye", Context.MODE_PRIVATE);
    sp.edit().putString(key, values).commit();
}

From source file:Main.java

public static void putBoolean(Context context, String key, boolean values) {
    SharedPreferences sp = context.getSharedPreferences("7Yan", context.MODE_PRIVATE);
    sp.edit().putBoolean(key, values).commit();
}

From source file:Main.java

public static long getLongPref(Context context, String name, long def) {
    SharedPreferences prefs = context.getSharedPreferences(APPLICATION_NAME, Context.MODE_PRIVATE);
    return prefs.getLong(name, def);
}

From source file:Main.java

public static void setUseCelsius(Context context, boolean use_celsius) {
    SharedPreferences pref = context.getSharedPreferences(SETTINGS_PREF, Context.MODE_PRIVATE);
    pref.edit().putBoolean(PREF_USE_CELSIUS, use_celsius).commit();
}

From source file:Main.java

public static int getIntValue(Context context, String key, int defValue) {
    SharedPreferences sp = context.getSharedPreferences(CONFIG_NAME, Context.MODE_PRIVATE);
    return sp.getInt(key, defValue);
}

From source file:Main.java

public static void putString(Context mContext, String key, String value) {
    SharedPreferences sp = mContext.getSharedPreferences("atguigu", Context.MODE_PRIVATE);
    sp.edit().putString(key, value).commit();
}

From source file:Main.java

public static void storeLong(Context context, String key, long value) {
    SharedPreferences pre = context.getSharedPreferences(STORE_NAME, Context.MODE_PRIVATE);
    pre.edit().putLong(STORE_KEY_PREFIX + key, value).commit();
}

From source file:Main.java

public static void saveCache(Context context, String key, String result) {
    SharedPreferences sp = context.getSharedPreferences("cacheUtils", Context.MODE_PRIVATE);
    sp.edit().putString(key, result).apply();
}

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   www . j  av  a2 s .  co m*/
    editor.apply();
}