Java tutorial
//package com.java2s; import android.content.Context; import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; public class Main { public static void putValueToSP(Context context, String key, Object obj) { SharedPreferences sp = getSharedPreferences(context); Editor editor = sp.edit(); if (obj instanceof String) { editor.putString(key, (String) obj); } else if (obj instanceof Integer) { editor.putInt(key, (Integer) obj); } else if (obj instanceof Boolean) { editor.putBoolean(key, (Boolean) obj); } else if (obj instanceof Float) { editor.putFloat(key, (Float) obj); } else if (obj instanceof Long) { editor.putLong(key, (Long) obj); } editor.commit(); } public static SharedPreferences getSharedPreferences(Context context) { return context.getSharedPreferences("config", Context.MODE_PRIVATE); } }