Why does viewModelScope.launch run on the main thread by default
ViewModelScope.launch { } runs on the main thread, but also gives you the option to run other dispatchers, so you can have UI & Background operations running synchronously. For you example: fun thisWillRunOnMainThread() { viewModelScope.launch { //below code will run on UI thread. showLoadingOnUI() //using withContext() you can run a block of code on different … Read more