I have 2 views in my app. A form input and a screen to review the form data and confirm. The user inputs the data on the form submission screen in edittext fields. When the user clicks submit, they are presented with the data they input and a ‘back’ and ‘confirm’ button. I want it so that if the user presses back, they are returned to the form input screen and the data they input should still be in the editText fields.
At the moment, I am using an onClickListener to point to the form submission screen but the forms are all blank. How do I keep the data in them?
This is the onClickListener:
bBack.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent j = new Intent(FormConfirm.this, FormCreate.class);
startActivity(j);
}
});
As stated you should save the values somehow, for example by using SharedPreferences.
As an example, when you go from the
Input-form Activity to theSubmit-form Activity:Where the method
saveInput()could look something like:And then, when you press back, the back action could simply be something like:
That will cause the current activity to exit and your previous activity will be visible. If you want to display the last saved input when the
Input-form Activity starts, you can simply do something like this:and call that method in the
onCreate-method in yourInput-form Activity.