60.8 Launching ActivityB as a Sub-Activity
In order for ActivityB to be able to return data to MainActivity, ActivityB must be started as a sub-activity of MainActivity. This means that the call to startActivity() in the MainActivity returnText() method needs to be replaced with a call to startActivityForResult(). Unlike the startActivity() method, which takes only the intent object as an argument, startActivityForResult() requires that a request code also be passed through. The request code can be any number value and is used to identify which sub-activity is associated with which set of return data. For the purposes of this example, a request code of 5 will be used, giving us a modified MainActivity class that reads as follows:
package com.ebookfrenzy.explicitintent
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import kotlinx.android.synthetic.main.activity_main...