60.8 Launching SecondActivity as a Sub-Activity
In order for SecondActivity to be able to return data to MainActivity, SecondActivity must be started as a sub-activity of MainActivity. This means that we need to call registerForActivityResult() and declare a callback handler to be called when SecondActivity returns. This callback will extract the data returned by SecondActivty and display it on textView1.
The call to registerForActivityResult() returns an ActivtyResultLauncher instance which can be called from within sendText() to launch the intent. Edit the MainActivity.kt file so that it reads as follows:
.
.
import androidx.activity.result.ActivityResult
import androidx.activity.result.contract.ActivityResultContracts
.
.
class MainActivity : AppCompatActivity() {
.
.
val startForResult = registerForActivityResult(
...