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 boolean getBoolean(Context ctx, String key, boolean defValue) {
    SharedPreferences sp = ctx.getSharedPreferences("config", Context.MODE_PRIVATE);
    return sp.getBoolean(key, defValue);
}

From source file:Main.java

public static void setString(Context ctx, String key, String value) {
    SharedPreferences sp = ctx.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
    sp.edit().clear();//w  w  w. ja  v  a  2  s  .com
    sp.edit().putString(key, value).commit();
}

From source file:Main.java

private static void getSharedPreferences(Context context) {
    if (sp == null) {
        sp = context.getSharedPreferences("config", context.MODE_PRIVATE);
    }/*from  w w  w .  j av a 2  s.  c om*/
}

From source file:Main.java

public static long getLastRefreshTime(Context context, String string) {
    SharedPreferences dePreferences = context.getSharedPreferences("refresh_time", 0);
    return dePreferences.getLong(string, 0);
}

From source file:Main.java

public static void clean(Context cxt, String fileName) {
    SharedPreferences preference = cxt.getSharedPreferences(fileName, Context.MODE_PRIVATE);
    Editor editor = preference.edit();/*  w ww.j a  v a2s .  co  m*/
    editor.clear();
    editor.commit();
}

From source file:Main.java

public static boolean hasAsymmericMasterSecret(Context context) {
    SharedPreferences settings = context.getSharedPreferences(PREFERENCES_NAME, 0);
    return settings.contains(ASYMMETRIC_LOCAL_PUBLIC_DJB);
}

From source file:Main.java

public static void putPlaymode(Context context, String key, int value) {
    SharedPreferences sp = context.getSharedPreferences("atguigu", Context.MODE_PRIVATE);
    sp.edit().putInt(key, value).commit();

}

From source file:Main.java

public static void setBoolean(Context ctx, String key, boolean value) {
    SharedPreferences spf = ctx.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
    spf.edit().putBoolean(key, value).commit();
}

From source file:Main.java

public static String getSharedPreferences(Context ctx, String groupkey, String key) {
    SharedPreferences pref = ctx.getSharedPreferences(groupkey, 0);
    return pref.getString(key, "");
}

From source file:Main.java

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