Java tutorial
//package com.java2s; //License from project: Apache License import android.content.Context; import android.content.SharedPreferences; import android.preference.PreferenceManager; import android.util.Log; public class Main { /** * to retrieve a value from sharedpreference * * @param context context of calling activity * @param key key whose value is to be fetchs * @return value or null if key not found */ public static String getPreference(Context context, String key) { return getPreference(context, key, null); } /** * to retrieve a value from sharedpreference * * @param context context of calling activity * @param key key whose value is to be fetchs * @param defaultValue to be returned if key not found * @return value or defaultvalue if key not found */ public static String getPreference(Context context, String key, String defaultValue) { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); String value = preferences.getString(key, defaultValue); logD("got key:" + key + " value:" + value); return value; } /** * log debug a string * * @param s string to be logged */ public static void logD(String s) { logD("LOG", s); } /** * log debug a string * * @param tag tag for logging * @param s string to be logged */ public static void logD(String tag, String s) { Log.d(tag, s); } }