Java tutorial
//package com.java2s; import android.content.Context; import android.content.SharedPreferences; public class Main { public static String PREFERENCE_NAME = "sqb"; /** * get long preferences * * @param context * @param key The name of the preference to retrieve * @return The preference value if it exists, or -1. Throws ClassCastException if there is a preference with this * name that is not a long * @see #getLong(Context, String, long) */ public static long getLong(Context context, String key) { return getLong(context, key, -1); } /** * get long preferences * * @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 long */ public static long getLong(Context context, String key, long defaultValue) { SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE); return settings.getLong(key, defaultValue); } }