在Android中我们通常使用 一个轻量级的存储类——SharedPreferences来保存用户偏好的参数!SharedPreferences也是使用xml文件, 然后类似于Map集合,使用键-值的形式来存储数据;
可以将什么数据放入SharedPreferences?
原始基本数据,不可以复合型的数据
boolean float int long String
简单存进一个数据
String user = "root";
String pwd = "123456";
String pass="123456";
// 获取SharePreferences对象 创建配置文件名
SharedPreferences sp1=getSharedPreferences("loginfo",MODE_PRIVATE);
//调用.edit()获取editor对象
SharedPreferences.Editor editor=sp1.edit();
//将不同的类型写入,参数是键值对的形式
editor.putString("user",user);
editor.putString("pwd",pwd);
editor.putString("pass",pass);
//提交数据,把数据提交到xml中
editor.