Here you can find the source of getPrefInt(SharedPreferences pref, String key, String default_value)
public static int getPrefInt(SharedPreferences pref, String key, String default_value)
import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; import android.content.pm.ApplicationInfo; import android.content.pm.PackageInfo; import android.net.wifi.WifiManager; import android.os.Environment; import android.preference.PreferenceManager; import java.io.File; import java.io.FileInputStream; import java.io.ObjectInputStream; import java.text.SimpleDateFormat; import java.util.Map; import java.util.Map.Entry; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; public class Main{ public static int getPrefInt(SharedPreferences pref, String key, int default_value) { Object value = getPrefObject(pref, key); int ret = default_value; if (value != null && value instanceof String) { String str = (String) value; if (MyStringUtlis.isEmpty(str) == false) { try { ret = Integer.parseInt(str); } catch (Throwable e) { Logger.w("invalid value, key=" + key + ", value=" + str); }/*from w w w.j av a 2 s . c o m*/ } } return ret; } public static int getPrefInt(SharedPreferences pref, String key, String default_value) { int ret = getPrefInt(pref, key, Integer.MIN_VALUE); if (ret == Integer.MIN_VALUE) { ret = Integer.parseInt(default_value); } return ret; } protected static Object getPrefObject(SharedPreferences pref, String key) { Map<String, ?> all = pref.getAll(); if (all != null) { Object obj = all.get(key); return obj; } return null; } }