Android 带着用户名的SharedPreferences

  /**
* 设置当前用户的签到信息
* account&info;account&info
*
* @param context
* @param sign
* @author jrjin
* @time 2016-1-5 下午2:27:47
*/
public static void setSignInfo(Context context, String sign) {
String account = getAccount(context);
if (TextUtils.isEmpty(account)) return;
String signs = getSigninfos(context);
if (TextUtils.isEmpty(signs)) {
signs = account + "&" + sign;
} else {
StringBuilder builder = new StringBuilder();
String[] modules = signs.split(";");
String[] time = null;
boolean added = false;
for (String module : modules) {
time = module.split("&");
if (time[].equals(account)) {
builder.append(account + "&" + sign + ";");
added = true;
} else {
// 直接添加
builder.append(module + ";");
}
}
if (!added) {
builder.append(account + "&" + sign + ";");
}
// 去除最后一个";"
signs = builder.toString();
signs = signs.substring(, signs.length() - );
} SharedPreferences sp = context.getSharedPreferences(
SETTING_PREFERENCES, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sp.edit();
editor.putString(PREFERENCE_KEY_SIGN_INFO, signs);
editor.commit();
} private static String getSigninfos(Context context) {
SharedPreferences sp = context.getSharedPreferences(
SETTING_PREFERENCES, Context.MODE_PRIVATE);
String signs = sp.getString(PREFERENCE_KEY_SIGN_INFO, "");
return signs;
}
上一篇:第六十九天 dom与bom


下一篇:九度OJ 1525 子串逆序打印 -- 2012年Google校园招聘笔试题目