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 void setParam(Context context, String key, Object object) { String type = object.getClass().getSimpleName(); SharedPreferences sp = context.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE); SharedPreferences.Editor editor = sp.edit(); if ("String".equals(type)) { editor.putString(key, (String) object); } else if ("Integer".equals(type)) { editor.putInt(key, (Integer) object); } else if ("Boolean".equals(type)) { editor.putBoolean(key, (Boolean) object); } else if ("Float".equals(type)) { editor.putFloat(key, (Float) object); } else if ("Long".equals(type)) { editor.putLong(key, (Long) object); } editor.commit(); } }