Java tutorial
//package com.java2s; //License from project: Open Source License import android.content.Context; import android.content.SharedPreferences; import android.preference.PreferenceManager; public class Main { /** * Return int value of shared preference specifies by key * @param context * @param key * @return */ public static int getSharedPreferenceInt(Context context, String key) { int result = -1; if (context != null) { SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); if (sharedPreferences != null) { result = sharedPreferences.getInt(key, -1); } } return result; } }