53.9 Returning Data from a Sub-Activity
SecondActivity is now launched as a sub-activity of MainActivity, which has, in turn, been modified to handle data returned from SecondActivity. All that remains is to modify SecondActivity.java to implement the finish() method and to add code for the returnText() method, which is called when the “Return Text” button is touched. The finish() method is triggered when an activity exits (for example when the user selects the back button on the device):
public void returnText(View view) {
finish();
}
@Override
public void finish() {
Intent data = new Intent();
String returnString = binding.editText2.getText().toString();
data.putExtra("returnData", returnString);
...