Java tutorial
//package com.java2s; import android.content.Context; import android.content.SharedPreferences; public class Main { public static Object getData(Context context, String fileName, String key, Class clazz) { SharedPreferences sharedPreferences = context.getSharedPreferences(fileName, Context.MODE_PRIVATE); if (clazz.getName().equals(String.class.getName())) { return sharedPreferences.getString(key, ""); } else if (clazz.getName().equals(Integer.class.getName())) { return sharedPreferences.getInt(key, 0); } else if (clazz.getName().equals(Float.class.getName())) { return sharedPreferences.getFloat(key, 0); } else if (clazz.getName().equals(Long.class.getName())) { return sharedPreferences.getLong(key, 0); } else { return sharedPreferences.getBoolean(key, false); } } }