In Activity A, I can view a string
. There is an EDIT button I press in Activity A that starts Activity B (and closes A). I pass the string with an intent from A to B in my onCreate
code like this:
In Activity A I have:
//for the edit button
edit = (Button) findViewById(R.id.edit);
edit.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
//open the Edit Activity, pass over the string
Intent i = new Intent(ViewContact.this, EditContact.class);
i.putExtra("category", categoryname.getText());
//start Activity B
startActivity(i);
//close Activity A
finish();
}
});
In Activity B I have:
Intent i = this.getIntent();
category = i.getStringExtra("category");
//set the EditText to display the value of "category" key
categoryname.setText(category);
All works so far. But if my back button is pressed in Activity B to go back to A, I want to show the string
again. As it stands, there is no value in the text box.
Back button code in Activity B:
//for the back arrow, tell it to close the activity, when clicked
ImageView backButton = (ImageView) logo.findViewById(R.id.back_arrow_id);
backButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i = new Intent(getApplicationContext(), ViewContact.class);
i.putExtra("category", categoryname.getText());
//Start Activity A
startActivity(i);
//Finish Acitivity B
finish();
}
});
And then when Activity A starts again it should call the intent in onCreate
with
Intent i = this.getIntent();
category = i.getStringExtra("category");
categoryname = (TextView) findViewById(R.id.textViewCategory);
categoryname.setText(category);
But instead the text box is empty.
Can you to tell me how I should go about passing the value back from B to A?