Java tutorial
//package com.java2s; //License from project: Apache License import android.content.Context; import android.content.SharedPreferences; import android.preference.PreferenceManager; public class Main { /** * Saves a string value under the provided key in the preference manager. If <code>value</code> * is <code>null</code>, then the provided key will be removed from the preferences. */ public static void saveStringToPreference(Context context, String key, String value) { SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context); if (null == value) { // we want to remove pref.edit().remove(key).apply(); } else { pref.edit().putString(key, value).apply(); } } }