Java tutorial
//package com.java2s; import android.content.Context; import android.content.SharedPreferences; import android.preference.PreferenceManager; public class Main { /** * Gets the preference. * * @param key the key * @param defaultValue the default value * @return the preference */ public static int getPreference(String key, int defaultValue, Context c) { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(c); return preferences.getInt(key, defaultValue); } /** * Gets the preference. * * @param key the key * @param defaultValue the default value * @return the preference */ public static String getPreference(String key, String defaultValue, Context c) { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(c); return preferences.getString(key, defaultValue); } /** * Gets the preference. * * @param key the key * @param defaultValue the default value * @return the preference */ public static boolean getPreference(String key, boolean defaultValue, Context c) { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(c); return preferences.getBoolean(key, defaultValue); } public static long getPreference(String key, long defaultValue, Context c) { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(c); return preferences.getLong(key, defaultValue); } public static float getPreference(String key, float defaultValue, Context c) { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(c); return preferences.getFloat(key, defaultValue); } }