Java tutorial
//package com.java2s; import android.content.Context; import android.content.SharedPreferences; import android.preference.PreferenceManager; import android.text.TextUtils; public class Main { private static final String PREF_ACTIVE_ACCOUNT = "chosen_account"; private static final String PREFIX_PREF_PLUG_COVER_URL = "plus_cover_url"; public static void setPlusCoverURL(Context context, final String accountName, String coverPhotoUrl) { SharedPreferences sp = getSharedPreferences(context); sp.edit().putString(makeAccountSpecificPrefKey(accountName, PREFIX_PREF_PLUG_COVER_URL), coverPhotoUrl) .apply(); } private static SharedPreferences getSharedPreferences(final Context context) { return PreferenceManager.getDefaultSharedPreferences(context); } public static String makeAccountSpecificPrefKey(Context context, String prefix) { return hasActiveAccount(context) ? makeAccountSpecificPrefKey(getActiveAccountName(context), prefix) : null; } public static String makeAccountSpecificPrefKey(String accountName, String prefix) { return prefix + accountName; } public static boolean hasActiveAccount(final Context context) { return !TextUtils.isEmpty(getActiveAccountName(context)); } public static String getActiveAccountName(final Context context) { SharedPreferences sp = getSharedPreferences(context); return sp.getString(PREF_ACTIVE_ACCOUNT, null); } }