使用SharedPreferences保存和获取信息

//保存信息

SharedPreferences sp = context.getSharedPreferences("config", Context.MODE_PRIVATE);  //Context.MODE_PRIVATE 私有类型
Editor editor = sp.edit();

//保存数据
editor.putString("username", username);
editor.putString("password", password);

//提交
editor.commit();

//获取信息

SharedPreferences sp = getSharedPreferences("config", MODE_PRIVATE);

//获取数据

username_et.setText(sp.getString("username", ""));
password_et.setText(sp.getString("passwrd", ""));

原文地址:https://www.cnblogs.com/zhangshan/p/4470620.html