Android本地存储

1. 存储数据

SharedPreferences preferences = Activity(当前).this.getSharedPreferences("LoginInfor",MODE_PRIVATE);

SharedPreferences.Editor editor = preferences.edit();

editor.putString("userName",UserStr);

editor.putString("passWord",PassWordStr);

editor.commit();


2. 读取数据

SharedPreferences pref = getSharedPreferences("LoginInfor",MODE_PRIVATE);

String name = pref.getString("userName",”“);//第二个参数为默认值

intage = pref.getInt(“age”,0);//第二个参数为默认值

booleanmarried = pref.getBoolean(“bool”,false);//第二个参数为默认值

推荐阅读更多精彩内容