Android 永久保存简单数据
转载: http://blog.csdn.net/xzlawin/article/details/45959033
方法1:
存数据:
SharedPreferences userInfo = this.getSharedPreferences("user_info", 0);
userInfo.edit().putString("name", nameet.getText().toString()).commit();
userInfo.edit().putString("password", passwordet.getText().toString()).commit();
读数据
SharedPreferences userInfo = this.getSharedPreferences("user_info", 0);
nameet.setText(userInfo.getString("name", ""));
passwordet.setText(userInfo.getString("password", ""));
方法2:
存数据:
SharedPreferences setting = getSharedPreferences("setting", 0);
SharedPreferences.Editor editor = setting.edit();
editor.putString("apiUrl", "hello").commit();
读数据
SharedPreferences setting = getSharedPreferences("setting", 0);
String apiUrl=setting.getString("apiUrl","");