使用 SharedPreferences记住密码

来源:互联网 发布:mac 查看命令路径 编辑:程序博客网 时间:2024/06/05 17:53
1.定义sp
private SharedPreferences sp = null;
2.在oncreate函数中
sp = this.getSharedPreferences("userinfo", Context.MODE_PRIVATE);    if (sp.getBoolean("auto", false))  {    ed_username.setText(sp.getString("uname", null));    ed_pw.setText(sp.getString("upswd", null));       auto.setChecked(true);         }
3.判断checkbox是否选中
//记住密码boolean autoLogin = auto.isChecked();if (autoLogin){Editor editor = sp.edit();editor.putString("uname", _username);editor.putString("upswd", _pw);editor.putBoolean("auto", true);editor.commit();}else{  Editor editor = sp.edit();editor.putString("uname", null);editor.putString("upswd", null);editor.putBoolean("auto", false);editor.commit();}

                                             
0 0
原创粉丝点击