avoid modifying serversCache serverList from multithreading

Bug: app force close during updating subscribe

Reroduce steps: quickly scroll up and down the RecyclerView during updating subscribe
if the server list length is more than the screen height, the bug can be 100% reproduced

Solution: reloadServerList from UI Thread

Signed-off-by: zhaoguomanong <zhaoguomanong@gmail.com>
This commit is contained in:
zhaoguomanong
2022-08-12 11:04:23 +08:00
parent b6aec3fd63
commit 8b76a7a4f4

View File

@@ -54,13 +54,9 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
fun reloadServerList() {
serverList = MmkvManager.decodeServerList()
viewModelScope.launch(Dispatchers.Default) {
updateCache()
launch(Dispatchers.Main) {
updateListAction.value = -1
}
}
}
fun removeServer(guid: String) {
serverList.remove(guid)