验证本地是否有已登录信息
1.验证是否已经登录
/**
* 判断用户是否已经登录
*/
private void isLogin()
{
// 查看本地是否有用户的登录信息
SharedPreferences sp = this.getActivity().getSharedPreferences("user_info", Context.MODE_PRIVATE);
String name = sp.getString("name", "");
if (TextUtils.isEmpty(name))
{
// 本地没有保存过用户信息,给出提示:登录
doLogin();
}
else
{
// 已经登录过,则直接加载用户的信息并显示
loadUserInfo();
}
}
/**
* @author: Hashub
* @WeChat: NGSHMVP
* @Date: 2018/9/2 19:46
* @function:缓存软件的一些参数和数据
*/
public class CacheUtils
{
/**
* 得到缓存值
*
* @param context 上下文
* @param key
* @return
*/
public static boolean getBoolean(Context context, String key)
{
SharedPreferences sp = context.getSharedPreferences("newsapp", Context.MODE_PRIVATE);
return sp.getBoolean(key, false);
}
/**
* 保存软件参数
*
* @param context
* @param key
* @param value
*/
public static void putBoolean(Context context, String key, boolean value)
{
SharedPreferences sp = context.getSharedPreferences("newsapp", Context.MODE_PRIVATE);
sp.edit().putBoolean(key, value).commit();
}
}
网友评论