Skip to content

Commit 7e966fe

Browse files
committed
fix: prevent nullifying instance when multiple MainViewModel instances exist
1 parent 5d6f324 commit 7e966fe

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

app/src/main/kotlin/li/songe/gkd/MainViewModel.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,11 @@ class MainViewModel : BaseViewModel(), OnSimpleLife {
7373

7474
init {
7575
_instance = this
76-
addCloseable { _instance = null }
76+
addCloseable {
77+
if (_instance == this) { // 可能同时存在 2 个 MainViewModel 实例
78+
_instance = null
79+
}
80+
}
7781
}
7882

7983
override val scope: CoroutineScope

0 commit comments

Comments
 (0)