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 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 int getSharedPreferencesInt(Context context, String key, int _default) {
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
    return preferences.getInt(key, _default);
}

From source file:Main.java

public static void saveLongSPR(String key, Long value, Context context) {
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
    SharedPreferences.Editor editor = preferences.edit();

    editor.putLong(key, value);/*from  w  ww .j a v a 2 s.  c  o  m*/

    editor.commit();

}

From source file:Main.java

public static void setReferenceString(String key, String value, Context context) {
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
    SharedPreferences.Editor editor = settings.edit();
    editor.putString(key, value);//w  w w  . j a va 2 s  . c om
    editor.commit();
}

From source file:Main.java

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

From source file:Main.java

public static void putSharedPreferencesLong(Context context, String key, long val) {
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
    SharedPreferences.Editor edit = preferences.edit();
    edit.putLong(key, val);
    edit.commit();//from   w ww.j  av a2 s . c o m
}

From source file:Main.java

public static void putSharedPreferencesInt(Context context, String key, int value) {
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
    SharedPreferences.Editor edit = preferences.edit();
    edit.putInt(key, value);// ww w .j a  va 2  s .  c  o m
    edit.apply();
}

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 long getSharedPreferencesLong(Context context, String key, long _default) {
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
    return preferences.getLong(key, _default);
}

From source file:Main.java

public static void putString(Context context, String key, String value) {
    try {//from   w  w w. j  ava2s. co m
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
        sp.edit().putString(key, value).apply();
    } catch (Exception e) {
        e.printStackTrace();
    }
}