https://kotlinlang.org logo
#android
Title
# android
o

oday

07/27/2022, 1:44 PM
anyone tried to use the new way of
startActivityForResult
? I have an Activity A that I start a Fragment A-2 inside, and that fragment A-2 starts another activity B, I need activity B to send back the result all the way to activity A using this new registerActivityForResult way
😶 2
so i have something like this inside activity A
Copy code
private val getSelectedDateRange: ActivityResultLauncher<Intent> = registerForActivityResult(
        ActivityResultContracts.StartActivityForResult()
    ) {
        if (it.resultCode == Activity.RESULT_OK) {
            val value =
                it.data?.getParcelableExtra<DateRange>(DateRangePickerActivity.ARG_DATE_RANGE)

            Log.d("DATE_RANGE", "Date range is ${value?.startDate} and ${value?.endDate}")
        }
    }
and I call this
getSelectedDateRange.launch
from inside the Fragment A-2 so it can start activity B, then in activity B I setResult when I’m done producing the result, then close the activity and the A-2 fragment behind it, activity A does not receive this result in the above receiver
11 Views