77.4 Adding the Activity Launchers
Following the steps outlined in the chapter entitled “Android Explicit Intents – A Worked Example”, we need to begin by registering activity launchers to handle the creation, opening and saving of file content. Within the MainActivity.kt file, add a launcher for each of the three actions as follows:
.
.
import androidx.activity.result.ActivityResult
import androidx.activity.result.contract.ActivityResultContracts
.
.
val startOpenForResult = registerForActivityResult(
ActivityResultContracts.StartActivityForResult()) {
result: ActivityResult ->
if (result.resultCode == Activity.RESULT_OK) {
result.data?.let {
&...