I have two Activities (A and B). Activity A consists of two EditText (1 and 2). I have an intent to launch Activity B from A. Then, from Activity B, I have an intent to pass a string to EditText2.
My problem now is, after passing an intent from Activity B to EditText2, the word that I typed in EditText1 disappears. My question is, how can I maintain a word that I typed in EditText1 even after passing an intent from Activity B to EditText2. Here's the cycle of my problem:
Typed something in EditText1 > Launch Activity B > get string from Activity B and pass it in EditText2 > typed word in EditText1 disappears
Here's my code:
Activity A:
public class ActivityA extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_a);
Intent intent = getIntent();
String message = intent.getStringExtra(ActivityB.EXTRA_MESSAGE);
EditText editText = (EditText) findViewById(R.id.edittext2);
editText.setText(message);
}
public void to_actb(View view) {
Intent intent = new Intent(this, ActivityB.class);
startActivity(intent);
}
Activity B
public class ActivityB extends Activity {
public final static String EXTRA_MESSAGE = "hello.hey.MESSAGE";
....
public void to_acta(View view) {
Intent intent = new Intent(this, ActivityA.class);
TextView textView = (TextView) findViewById(R.id.text);
String message = textView.getText().toString();
intent.putExtra(EXTRA_MESSAGE, message);
startActivity(intent);
}