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 setStringPreferences(Context context, String name, String value) { try { SharedPreferences.Editor editor = context .getSharedPreferences(SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE).edit(); editor.putString(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() + ""); } } }