3.21
所花时间:1小时
代码量:11
博客篇:1
实现登录时保存用户信息
使用SharedPreference对象
数据的保存:
SharedPreferences sharedPreferences = getSharedPreferences("user",MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("id",s.getId());
editor.putString("name",s.getName());
editor.putString("phnumber",s.getPhnumber());
editor.putString("unit",s.getUnit());
editor.commit();
数据的提取:
SharedPreferences sharedPreferences = getSharedPreferences("user",MODE_PRIVATE);
id = sharedPreferences.getString("id","");
name = sharedPreferences.getString("name","");
unit = sharedPreferences.getString("unit","");