androidfragmentregisterforactivityresult

How to launch ActivityResultLauncher for picking contact?


I need to get contact info from activity which is out of my app. I read doc and try getting info as doc says. I can't understand what argument I must pass to launch method of ActivityResultLauncher.

private val getContact = registerForActivityResult(
    ActivityResultContracts.PickContact()
) { uri: Uri? ->
    Log.d(TAG, uri.toString())
}

....

button.setOnClickListener {
    getContact.launch() // here launch requires argument of type Void?
}

Solution

  • You can pass in null or use the extension method from activity-ktx specifically for ActivityResultLauncher<Void?> that means you don't need to pass anything at all:

    import androidx.activity.result.launch