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_PLUS_IMAGE_URL = "plus_image_url_"; public static String getPlusNameImageURL(Context context) { SharedPreferences sp = getSharedPreferences(context); return hasActiveAccount(context) ? sp.getString(makeAccountSpecificPrefKey(context, PREFIX_PREF_PLUS_IMAGE_URL), null) : null; } public static String getPlusNameImageURL(final Context context, final String accountName) { SharedPreferences sp = getSharedPreferences(context); return hasActiveAccount(context) ? sp.getString(makeAccountSpecificPrefKey(accountName, PREFIX_PREF_PLUS_IMAGE_URL), null) : null; } private static SharedPreferences getSharedPreferences(final Context context) { return PreferenceManager.getDefaultSharedPreferences(context); } public static boolean hasActiveAccount(final Context context) { return !TextUtils.isEmpty(getActiveAccountName(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 String getActiveAccountName(final Context context) { SharedPreferences sp = getSharedPreferences(context); return sp.getString(PREF_ACTIVE_ACCOUNT, null); } }