활동의 인스턴스 상태 저장 및 복원이 완전히 중단되었습니다. 여기에 내가 무엇을 가지고 : 나는 "라고 SAVE"의 출력을 얻고있다Android : 인스턴스 상태 저장/복원
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register1);
context = this;
input_first_name = (EditText) findViewById(R.id.first_name);
input_last_name = (EditText) findViewById(R.id.last_name);
input_email = (EditText) findViewById(R.id.register_email);
input_password = (EditText) findViewById(R.id.register_password);
input_cell = (EditText) findViewById(R.id.register_cell);
if (savedInstanceState != null) {
System.err.println(savedInstanceState.getString("first_name"));
input_first_name.setText(savedInstanceState.getString("first_name"));
input_last_name.setText(savedInstanceState.getString("last_name"));
input_email.setText(savedInstanceState.getString("email"));
input_password.setText(savedInstanceState.getString("password"));
input_cell.setText(savedInstanceState.getString("cell"));
}
...
}
protected void onSaveInstanceState(Bundle b) {
super.onSaveInstanceState(b);
System.err.println("save called");
b.putString("first_name", first_name);
b.putString("last_name", last_name);
b.putString("email", email);
b.putString("password", password);
b.putString("cell", cell);
}
protected void onRestoreInstanceState(Bundle b) {
System.err.println(b.getString("first_name"));
input_first_name.setText(b.getString("first_name"));
input_last_name.setText(b.getString("last_name"));
input_email.setText(b.getString("email"));
input_password.setText(b.getString("password"));
input_cell.setText(b.getString("cell"));
}
, 그래서 난 내 번들이 올바르게 저장되었다고 생각합니다. 그러나 나는 다시 활동으로 돌아 왔을 때 어떤 결과물도 보지 못했다. 누구든지 내가 뭘 잘못하고 있는지 알아? 감사!
@Override
protected void onSaveInstanceState(Bundle b) {
super.onSaveInstanceState(b);
System.err.println("save called");
b.putString("first_name", first_name);
b.putString("last_name", last_name);
b.putString("email", email);
b.putString("password", password);
b.putString("cell", cell);
}
우선, 기본값 (saveState.getString ("abc", "default"))을 지정하는보다 안전한 "get"메소드를 사용해야합니다. – samosaris
변수의 값 (first_name, ...)을 어디에도 설정하지 않습니다. –
'onRestoreInstanceState' 메소드는 액티비티가 다시 생성 될 때만 호출됩니다. 어떻게 활동을 모방 하는가? – nfirex