mvvmcoroutinesandflow icon indicating copy to clipboard operation
mvvmcoroutinesandflow copied to clipboard

ForecastsViewModel中的viewModelScope.launch()的block()不會被調用

Open tenSunFree opened this issue 5 years ago • 0 comments

Affected Device(s) [e.g. Samsung Galaxy s10 with Android 9.0] Answer︰HTC U11 with Android 9.0

Describe the Bug: Add a clear description about the problem. Answer︰ForecastsViewModel中的viewModelScope.launch()的block()不會被調用,下圖中的紅框內容不會被調用。 2020-01-17_002021

Expected Behavior: A clear description of what you expected to happen. Answer︰點擊Show Forecasts按鈕後,跳轉至ForecastsFragment。然後點擊返回鍵返回WeatherFragment後,再點擊Show Forecasts按鈕,ForecastsViewModel中的viewModelScope.launch()的block()不會被調用,目前看起來是因為觸發過ForecastsViewModel的onCleared()。

目前的解決方法,是將viewModelScope修改成GlobalScope,如下圖所示。你有什麼想法嗎?或是比較好的解決方法?謝謝。 2020-01-17_001909

tenSunFree avatar Jan 16 '20 16:01 tenSunFree