Jan Skrasek
10/09/2019, 1:04 PM2019-10-09 14:49:52.581 4418-4418/my.app.id E/AndroidRuntime: FATAL EXCEPTION: main
Process: my.app.id, PID: 4418
kotlinx.coroutines.JobCancellationException: Job was cancelled; job=SupervisorJobImpl{Cancelled}@b43ae6d
val myEvent = Channel<Unit>(Channel.RENDEZVOUS)
viewModel.myEvent.consumeAsFlow()
.onEach {
Toast.makeText(requireContext(), R.string.error, Toast.LENGTH_LONG).show()
}
.launchIn(lifecycleScope)
1. it is not obivous what caused the crash from the stack trace; emiting to closed channel?
2. how can I workaround it?Paul Woitaschek
10/09/2019, 1:12 PMlifecycleScope.launch {
consumeAsFlow.collect { Toast() }
}
Adam Powell
10/09/2019, 1:13 PMconsumeAsFlow
will cancel the channel when collection stops, and the lifecycleScope will be cancelled when your fragment is destroyed.
2. What behavior do you want here?myEvent
?Paul Woitaschek
10/09/2019, 1:13 PMJan Skrasek
10/09/2019, 1:25 PM