How to replace startActivityForResult with Activity Result APIs?

You can call as many Activities for result as you wish and have separate callback for each:

val startForResult = registerForActivityResult(
    ActivityResultContracts.StartActivityForResult()
) { result: ActivityResult ->
    if (result.resultCode == Activity.RESULT_OK) {
        //  you will get result here in result.data
    }
}

startForResult.launch(Intent(activity, CameraCaptureActivity::class.java))

You just need to specify Activity class – CameraCaptureActivity::class.java

Update:

The prepareCall() method has been renamed to
registerForActivityResult() in Activity 1.2.0-alpha04 and Fragment
1.3.0-alpha04. And it should be startForResult.launch(…) in the last line

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)