SharedPerferences 记住密码

来源:互联网 发布:php 获取系统信息 编辑:程序博客网 时间:2024/06/08 09:41

SharedPerferences android 五大存储方式之轻量级存储 

我常用语登陆界面的记住密码

存储:

//获取SharedPreferences对象 参数一:存储的名称 参数二 存储的模式 Activity.MODE_PRIVATE本应用可以获取信息SharedPreferences spf = getSharedPreferences("LoginUser" , Activity.MODE_PRIVATE) ;SharedPreferences.Editor editor = spf.edit() ;//得到editor(编辑)editor.putString("userName", str_username) ;//将用户名存入editor.putString("passWord", str_passwprd) ;//将密码存入editor.commit() ;

获取:

SharedPreferences spf = getSharedPreferences("LoginUser", Activity.MODE_PRIVATE) ;String str_userName = spf.getString("userName", "") ;String str_passWord = spf.getString("passWord", "") ;




0 0
原创粉丝点击