Slide 30
Slide 30 text
Coroutine Activity Results
interface ActivityResultMixin {
data class ActivityResult(val requestCode: Int, val resultCode: Int, val data: Intent?)
fun startActivityForResult(intent: Intent, requestCode: Int)
val _activityResultStream: PublishSubject
suspend fun startActivityForResultAsync(intent: Intent, requestCode: Int): ActivityResult {
startActivityForResult(intent, requestCode)
return _activityResultStream
.filter { it.requestCode == requestCode }
.awaitFirstOrDefault((ActivityResult(requestCode, Activity.RESULT_CANCELED, null)))
}
fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
_activityResultStream.onNext(ActivityResult(requestCode, resultCode, data))
}
fun onDestroy() {
_activityResultStream.onCompleted()
}
}