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 setSettingLong(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 clear(final Context context) {
    if (context != null) {
        final SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
        final SharedPreferences.Editor editor = settings.edit();
        editor.clear().commit();/*from   w  w  w . j  av  a 2  s.c o m*/
    }
}

From source file:Main.java

public static void putSharedPreferencesBoolean(Context context, String key, boolean val) {
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
    SharedPreferences.Editor edit = preferences.edit();
    edit.putBoolean(key, val);
    edit.commit();/*from w  ww. j a  va2s  .co  m*/
}

From source file:Main.java

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

From source file:Main.java

public static void setPrefBoolean(Context context, final String key, final boolean value) {
    final SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
    settings.edit().putBoolean(key, value).apply();
}

From source file:Main.java

public static void putSharedPreferencesBoolean(Context context, String key, boolean val) {
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
    SharedPreferences.Editor edit = preferences.edit();
    edit.putBoolean(key, val);
    edit.apply();//from  w  w w .j  a  va 2 s . c  o  m
}

From source file:Main.java

public static String getSharedPreferencesString(Context context, String key, String _default) {
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
    return preferences.getString(key, _default);
}

From source file:Main.java

public static long getLong(Context context, String key, long defaultValue) {
    try {/*from   w  w w.java2 s. c om*/
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
        return sp.getLong(key, defaultValue);
    } catch (Exception e) {
        e.printStackTrace();
        return defaultValue;
    }
}

From source file:Main.java

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

From source file:Main.java

public static float getFloat(Context context, final String key, final float defaultValue) {
    final SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
    return settings.getFloat(key, defaultValue);
}