Android开发,如何在退出Activity之后自动保存EditText当中输入的内容

2024-11-17 00:08:37
推荐回答(2个)
回答(1):

@Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
WriteUserInfo()
}

private void  WriteUserInfo()
{
SharedPreferences userInfo = getSharedPreferences("user_info",0);
SharedPreferences.Editor editor = userInfo.edit();
EditText userName = (EditText)findViewById(R.id.username);
editor.putString("username", userName.getText().toString());
editor.commit();
}

回答(2):

public boolean readAndDispatch () {
checkDevice ();