Example usage for android.content SharedPreferences getString

List of usage examples for android.content SharedPreferences getString

Introduction

In this page you can find the example usage for android.content SharedPreferences getString.

Prototype

@Nullable
String getString(String key, @Nullable String defValue);

Source Link

Document

Retrieve a String value from the preferences.

Usage

From source file:Main.java

public static float getLineSpacing(SharedPreferences preferences, String key, String defaultValue) {
    return Float.parseFloat(preferences.getString(key, defaultValue));
}

From source file:Main.java

public static int getPrefInt(SharedPreferences pref, String key, int def_value) {
    try {/*from  ww  w .  j a  v a2  s .  c  om*/
        String value = pref.getString(key, String.valueOf(def_value));
        return Integer.parseInt(value);
    } catch (Exception e) {
        // Do nothing
    }
    return def_value;
}

From source file:Main.java

public static String getHistoricValue(Context context) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);

    return prefs.getString("historic_range", "week");
}

From source file:Main.java

public static String getString(Context mContext, String key) {
    SharedPreferences sp = mContext.getSharedPreferences("atguigu", Context.MODE_PRIVATE);
    return sp.getString(key, "");
}

From source file:Main.java

public static String getStringPreference(Context context, String preferenceName, String key) {
    SharedPreferences sharedPreferences = context.getSharedPreferences(preferenceName, 0);
    return sharedPreferences.getString(key, null);
}

From source file:Main.java

public static String getString(Context context, String key, String defaultString) {
    SharedPreferences sp = context.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE);
    return sp.getString(key, defaultString);
}

From source file:Main.java

public static String getStringPrefs(Context context, String key) {
    SharedPreferences sp = context.getSharedPreferences(PRE_NAME, Context.MODE_PRIVATE);
    return sp.getString(key, "");

}

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

/**
 * get string preferences//from   w  w w .  j  a v  a 2 s .  c o  m
 * 
 * @param context
 * @param key The name of the preference to retrieve
 * @param defaultValue Value to return if this preference does not exist
 * @return The preference value if it exists, or defValue. Throws ClassCastException if there is a preference with
 *         this name that is not a string
 */
public static String getString(Context context, String key, String defaultValue) {
    SharedPreferences settings = getDefaultPreferences(context);
    return settings.getString(key, defaultValue);
}

From source file:Main.java

public static String getString(Context mContext, String key, String values) {
    SharedPreferences sp = mContext.getSharedPreferences(SHARE_NAME, Context.MODE_PRIVATE);
    return sp.getString(key, values);
}