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_NAME = "plus_name_"; public static String getPlusName(final Context context) { SharedPreferences sp = getSharedPreferences(context); return hasActiveAccount(context) ? sp.getString(makeAccountSpecificPrefKey(context, PREFIX_PREF_PLUS_NAME), 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); } }