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", "") ;