Java tutorial
//package com.java2s; //License from project: Open Source License import android.content.Context; import android.content.SharedPreferences; import java.util.HashMap; public class Main { private static Context context; private static final String PRIVATE_CACHE = "PRIVATE_CACHE"; public static void save(String key, String val) { SharedPreferences preferences = getPrivateSharedPreference(); SharedPreferences.Editor editor = preferences.edit(); editor.putString(key, val); editor.commit(); } public static void save(HashMap<String, String> map) { SharedPreferences preferences = getPrivateSharedPreference(); SharedPreferences.Editor editor = preferences.edit(); for (String key : map.keySet()) { editor.putString(key, map.get(key)); } editor.commit(); } public static SharedPreferences getPrivateSharedPreference() { return context.getSharedPreferences(PRIVATE_CACHE, Context.MODE_PRIVATE); } }