Example usage for android.preference PreferenceManager getDefaultSharedPreferences

List of usage examples for android.preference PreferenceManager getDefaultSharedPreferences

Introduction

In this page you can find the example usage for android.preference PreferenceManager getDefaultSharedPreferences.

Prototype

public static SharedPreferences getDefaultSharedPreferences(Context context) 

Source Link

Document

Gets a SharedPreferences instance that points to the default file that is used by the preference framework in the given context.

Usage

From source file:Main.java

public static void writeToPrefs(Context context, String key, String value) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    prefs.edit().putString(key, value).apply();
}

From source file:Main.java

public static int getInt(Context context, final String key, int defaultValue) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    return prefs.getInt(key, defaultValue);
}

From source file:Main.java

public static void putStringToDefault(Context context, String key, String value) {
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
    sp.edit().putString(key, value).commit();
}

From source file:Main.java

public static void remove(Context context, String key) {
    try {//  ww w  .ja v  a 2s  .  com
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
        sp.edit().remove(key).apply();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static SharedPreferences mGetSharedPreferences(Context pContext) {
    //   pContext.getSharedPreferences("PREFS", Context.MODE_PRIVATE);
    return PreferenceManager.getDefaultSharedPreferences(pContext);
}

From source file:Main.java

public static void putBooleanToDefault(Context context, String key, boolean value) {
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
    sp.edit().putBoolean(key, value).commit();
}

From source file:Main.java

public static void setInt(String key, Context context, int value) {
    SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(context).edit();
    editor.putInt(key, value);/*from   w ww.j a  va  2  s  . c  om*/
    editor.commit();
}

From source file:Main.java

public static void saveLoginInfo(Context context, String account, String pwd) {
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
    SharedPreferences.Editor editor = sp.edit();
    editor.putString("account", account);
    editor.putString("password", pwd);
    editor.commit();/* ww w.ja v  a  2 s  .  c om*/
}

From source file:Main.java

public static void deleteFromPref(Context context, String typeStr) {
    SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(context).edit();
    editor.remove(typeStr);//  w  w  w  .j ava  2 s.  c  o m
    editor.apply();
}

From source file:Main.java

public static long lastCheckUpdateTime(final Context context) {
    return PreferenceManager.getDefaultSharedPreferences(context).getLong(PREFERENCE_CHECKUPDTETIME, 0);
}