转自http://blog.sina.com.cn/s/blog_a73687bc0101dsjj.html
(一)使用SharedPreferences 
1、保存信息:
SharedPreferences userDetails = context.getSharedPreferences("userinfo", Context.MODE_PRIVATE);
Editor edit = userDetails.edit();
edit.clear();
edit.putString("phone", phoneEditText.getText().toString().trim());
edit.putString("password", passwordEditText.getText().toString().trim());
edit.commit();
2、读取信息:
SharedPreferences userDetails = context.getSharedPreferences("userinfo", Context.MODE_PRIVATE);
String phone = userDetails.getString("phone", "");
String password = userDetails.getString("password", "");
phoneEditText.setText(phone);
passwordEditText.setText(password);
注意:这里密码没有加密存储,实际应用中最好进行加密存储
posted on 2017-01-07 21:16  Total_MHP  阅读(309)  评论(0编辑  收藏  举报