Java tutorial
//package com.java2s; import android.content.Context; import android.content.SharedPreferences; import android.util.Log; public class Main { private final static String SHARED_PREFERENCE_NAME = "SC_SHARED_PREFERENCE"; public static void setBooleanPreferences(Context context, String name, boolean value) { try { SharedPreferences.Editor editor = context .getSharedPreferences(SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE).edit(); editor.putBoolean(name, value); editor.commit(); } catch (Exception e) { Log.e("datautils", e.getMessage()); remove(context, name); } } public static void remove(Context context, String name) { try { SharedPreferences.Editor editor = context .getSharedPreferences(SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE).edit(); editor.remove(name); editor.commit(); } catch (Exception e) { Log.e("datautils", e.getMessage() + ""); } } }