escodro
11/16/2022, 7:47 PMfun addItem(item: String) {
viewModelScope.launch {
repository.saveDataInRoom(item)
interactor.sendNotification(item)
interactor2.updateWidget(item)
}
}
The “addItem” screen is a Bottom Sheet that is dismissed after the user adds an item.
Since the saveDataInRoom()
is a heavy operation, by the time it ends the execution the coroutine was already cancelled by passing on ViewModel#onCleared()
. Then no code after that is executed after that command.
Any suggestions on how to ensure that everything is executed?
Thanks!Kevin Del Castillo
11/16/2022, 8:03 PMJavier
11/16/2022, 8:07 PMescodro
11/16/2022, 8:14 PMKevin Del Castillo
11/16/2022, 8:16 PMJavier
11/16/2022, 8:58 PMsuspend fun addItem
and call it with an activity lifecycle scopeAndre Theilacker
11/17/2022, 3:46 AMescodro
11/17/2022, 2:44 PMJhonatan Sabadi
11/18/2022, 12:13 PM