Текущая модель представления закрывается, что также закрывает всю функцию viewModelScope.launch до того, как все записи ⇐ Android
Текущая модель представления закрывается, что также закрывает всю функцию viewModelScope.launch до того, как все записи
I'm trying to learn how I should re-write my room database (dao, repository, viewmodel, room databse). My problem: The user pressed the save button on the UI, the onClick function does the following: 1 – Save records in the room database using the viewModelScope.launch function. 2 – Navigates to a different screen.
My question – what method you would use to wait for the viewModelScope.launch function to complete before navigates to the different screen. The issue I’m having is the current viewModel is closing which also closes all the viewModelScope.launch function before all of the records are saved.
onClick = { nextScreen = onSaveSelection() navHostController.navigate(route = Screen.ScoreCard.route) } fun onSaveSelection(): Int { deleteAllPlayerRecords() savePlayersRecord() saveScoreCardRecord() return Constants.DISPLAY_SCORE_CARD_SCREEN } I have read you shouldn’t use GlobalScope.launch function.
Thanks for the advice
Источник: https://stackoverflow.com/questions/780 ... ope-launch
I'm trying to learn how I should re-write my room database (dao, repository, viewmodel, room databse). My problem: The user pressed the save button on the UI, the onClick function does the following: 1 – Save records in the room database using the viewModelScope.launch function. 2 – Navigates to a different screen.
My question – what method you would use to wait for the viewModelScope.launch function to complete before navigates to the different screen. The issue I’m having is the current viewModel is closing which also closes all the viewModelScope.launch function before all of the records are saved.
onClick = { nextScreen = onSaveSelection() navHostController.navigate(route = Screen.ScoreCard.route) } fun onSaveSelection(): Int { deleteAllPlayerRecords() savePlayersRecord() saveScoreCardRecord() return Constants.DISPLAY_SCORE_CARD_SCREEN } I have read you shouldn’t use GlobalScope.launch function.
Thanks for the advice
Источник: https://stackoverflow.com/questions/780 ... ope-launch
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение