Android examples for android.content:SharedPreferences
set Shared Preference
import android.content.Context; import android.content.SharedPreferences; public class Main { public static final String PREFS_NAME = "_java2s.com"; public static void setSharedPreference(Context c, String preference, boolean prefValue) { SharedPreferences settings = c.getSharedPreferences(PREFS_NAME, 0); SharedPreferences.Editor editor = settings.edit(); editor.putBoolean(preference, prefValue); editor.commit();//from w w w . j a v a 2s .c o m } public static void setSharedPreference(Context c, String preference, String prefValue) { SharedPreferences settings = c.getSharedPreferences(PREFS_NAME, 0); SharedPreferences.Editor editor = settings.edit(); editor.putString(preference, prefValue); editor.commit(); } }