很多app中在第一次安装登陆时会有引导欢迎界面,第二次打开时就不再显示引导页面。
这个功能可以通过使用SharePreferences将用户的登陆信息保存起来,当app启动时判断登陆信息决定打开页面。
以下是创建的SharePreference类:
public class SharePreference {
Context context;
public SharePreference(Context context)
{
this.context = context;
}
/****设置状态 false为安装后第一次登录,true为已经登录过****/
public void setState()
{
SharedPreferences sp = context.getSharedPreferences("save.himi", Context.MODE_PRIVATE);
Editor editor = sp.edit();
editor.putBoolean("isLogin", true);
editor.commit();
}
/***获取状态***/
public boolean getState()
{
SharedPreferences sp = context.getSharedPreferences("save.himi", Context.MODE_PRIVATE);
boolean b = sp.getBoolean(&