AJ
05/27/2021, 6:54 PMgetViewModelScope().launch {
while (this.isActive) {
val dateString = calendarInteractor.getDateString()
dateStringFlow.value = dateString
log.debug { "sending date string to channel on thread " + ThreadInfo.currentThread() }
dateStringChannel.send(dateString)
delay(100)
}
}
And after going out of the app and returning I am always having a StandaloneCoroutine{Cancelled} for the sending to Channel part, how come? Why does it get cancelled? The launch block is called once and then stops.
Any clues would be appreciateddshevliakov
05/27/2021, 7:41 PMAJ
05/27/2021, 7:44 PMlifecycleScope.launch
in OnResume and then cancel it on OnPause, the coroutine is not launched again OnResumeAJ
05/27/2021, 7:52 PMAJ
05/27/2021, 7:57 PMCoroutineScope(Dispatchers.Main).launch
or with a job
CoroutineScope(Dispatchers.Main + SupervisorJob())
dshevliakov
05/27/2021, 8:02 PMdshevliakov
05/27/2021, 8:02 PMdshevliakov
05/27/2021, 8:03 PMlaunch
never starts a new coroutine at all?AJ
05/27/2021, 8:03 PMAJ
05/27/2021, 8:04 PMAJ
05/27/2021, 8:05 PMoverride fun onResume() {
super.onResume()
calendarViewModel.startSendingDateChanges()
listenToDateSubscription = lifecycleScope.launch {
calendarViewModel.dateStringChannel.consumeEach {
textView.text = it
}
}
}
this is my OnResume function, which calls the channel populating method and tries to consume itAJ
05/27/2021, 8:06 PMAJ
05/27/2021, 8:06 PMAJ
05/27/2021, 8:07 PMoverride fun onPause() {
super.onPause()
listenToDateSubscription?.cancel(“Activity paused”)
}this is my onPause call, which just cancels the Job, basically I am doing by hand what was done by addRepeatingJob
AJ
05/28/2021, 8:05 AMdshevliakov
05/28/2021, 8:08 AM