Java tutorial
//package com.java2s; //License from project: Open Source License import android.content.Context; import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; import android.os.Build; import android.preference.PreferenceManager; public class Main { /** * Sets a shared preference key to specified int value * @param context * @param key * @param value */ public static void putSharedPreferenceInt(Context context, String key, int value) { if (context != null) { SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); Editor edit = sharedPreferences.edit(); edit.putInt(key, value); if (Build.VERSION.SDK_INT >= 9) { edit.apply(); } else { edit.commit(); } } } }