Java tutorial
//package com.java2s; import android.content.Context; import android.content.SharedPreferences; public class Main { private static final String FILE_NAME = "share_date"; public static Object getParam(Context context, String key, Object defaultObject) { String type = defaultObject.getClass().getSimpleName(); SharedPreferences sp = context.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE); if ("String".equals(type)) { return sp.getString(key, (String) defaultObject); } else if ("Integer".equals(type)) { return sp.getInt(key, (Integer) defaultObject); } else if ("Boolean".equals(type)) { return sp.getBoolean(key, (Boolean) defaultObject); } else if ("Float".equals(type)) { return sp.getFloat(key, (Float) defaultObject); } else if ("Long".equals(type)) { return sp.getLong(key, (Long) defaultObject); } return null; } }