Download the source code or see the whole post
For the first action, you need to use the startActivityForResult () function, which returns the values ββof the parent activity, which is active.
Intent intent = new Intent(MainActivity.this, Activity2.class);
startActivityForResult(intent, 1);
And to get values ββfrom two actions without changing activity, add the following code
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 1) {
if(resultCode == RESULT_OK){
String text=data.getStringExtra("text");
vTxt.setText("Name 1: "+eTxt.getText()+ "\n Name 2: "+text);
}
}
}
Action 2
add the following code to return to activity 1 and pass some values
Intent intent=new Intent(Activity2.this, MainActivity.class);
Bundle extra=new Bundle();
extra.putString("text", eTxt.getText().toString());
intent.putExtras(extra);
setResult(RESULT_OK, intent);
finish();
Finally you are done
source
share