OnActivityResult Uri error

Looking at my solution, I modified the first line to be

val contactUri: Uri = data.data ?: return

If we do not have any data, then we cannot continue with the query so this helps protect our nullability. For greater scope, here is the larger function

when {
  resultCode != Activity.RESULT_OK -> return
  requestCode == REQUEST_CONTACT && data != null -> {
    val contactUri: Uri = data.data ?: return
    // the rest of the cursor & query calls
  }
  requestCode == REQUEST_PHOTO -> {
    // do photo stuff from Chapter 16
  }
}
6 Likes