Create two integer constants for your two requests , 1. Source address and 2. Destination address
final static int SOURCE_ADDRESS = 1;
final static int DESTINATION_ADDRESS = 2;
From your MainActivity call the MapActivity using startActivityForResult() method
In your listener call this as per the resource id of both the EditText
Intent i = new Intent(MainActivity.this, MapActivity.class);
switch(v.getId()){
case R.id.source:
startActivityForResult(i, SOURCE_ADDRESS);
break;
case R.id.destination:
startActivityForResult(i, DESTINATION_ADDRESS);
break;
In your MapActivity set the data which you want to return back to MainActivity.
Intent returnIntent = new Intent();
returnIntent.putExtra("address",result);
setResult(Activity.RESULT_OK,returnIntent);
finish();
Now in your MainActivity class write following code for the onActivityResult() method.
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK) {
String address=data.getStringExtra("address");
if(requestCode == SOURCE_ADDRESS){
//Assign the address to source address TextView
} else if (requestCode == DESTINATION_ADDRESS){
//Assign the address to destination address
}
} else {
//write code if no value is returned
}
}