你可以这样做
浏览这两个网址,这将对您有所帮助
沃杰拉
mobile.tutsplus.com
节省
public void saveInformation(String username,String password) {
SharedPreferences shared = getSharedPreferences("shared", MODE_PRIVATE);
SharedPreferences.Editor editor = shared.edit();
editor.putString("username", username);
editor.putString("password", password);
editor.commit();
}
加载
private void LoadPreferences(){
SharedPreferences sharedPreferences = getPreferences(MODE_PRIVATE);
String username = sharedPreferences.getString("username", "");
String password = sharedPreferences.getString("password", "");
}
编辑
private void editDate(){
SharedPreferences.Editor editor = getPreferences(MODE_PRIVATE).edit();
editor.putString("username", mSaved.getText().toString());
editor.putInt("selection-start", mSaved.getSelectionStart());
editor.putInt("selection-end", mSaved.getSelectionEnd());
editor.commit();
}
要保存多个用户数据,建议您为每个用户创建多个文件,然后将其保存在共享首选项中
只需从此处 了解getDefaultSharedPreferences 和getSharedPreferences之间的差异Diffrence Link