SharedPreference数据存储
Java代码
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//获取一个SharedPreferences对象
SharedPreferences sp = getSharedPreferences("dataInfo", 0);
String user = sp.getString("user", "");
String password = sp.getString("password", "");
((EditText)findViewById(R.id.user)).setText(user);
((EditText)findViewById(R.id.password)).setText(password);
}
@Override
protected void onStop() {
super.onStop();
SharedPreferences sp = getSharedPreferences("dataInfo", 0);
sp.edit().putString("user",
((EditText)findViewById(R.id.user)).getText().toString())
.putString("password",
((EditText)findViewById(R.id.password)).getText().toString())
.commit();
}
作者“rayln”
补充:移动开发 , Android ,