Totally stuck saving and restoring instance state of an activity. Here is what I have:
@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"));
}
I'm getting output for "save called", so I think that my bundle was saved correctly. However, I'm never seeing any output when I come back into the activity. Anyone see what I am doing wrong? Thanks!