-
-
Notifications
You must be signed in to change notification settings - Fork 771
Description
Describe the bug
Happy to be told its something im doing wrong but this seems very strange to me took me a while to track down the cause but basically ViewModels getting corrupted ? on use on popBackStack or swipe left when created vm singletons using singleOf(::NameViewModel), leaving the viewmodel not able to launch coroutines. Am guessing its just because detailscreen goes out of scope with VM attached to it, but as its a singleton it should still be available elsewhere ?
To Reproduce
Steps to reproduce the behavior:
- Create vm using singleOf(::NameViewModel)
- Add two screens that navigate from one to other
- reference vm in 2nd screen and 1st (should be same vm)
- use swipe left on android to navigate back to root screen (or can use popBackStack on a button)
Expected behavior
vm is still available to launch coroutines in vm. Coroutine just don't start
`
class MyViewModel : ViewModel() {
var name = "Hello"
private var _coroutineRunCount = MutableStateFlow(0)
var coroutineRunCount : StateFlow = _coroutineRunCount
fun runCoroutine() {
println("runCoroutine")
viewModelScope.launch {
println("runCoroutine - Launched *****")
_coroutineRunCount.value += 1
}
}
}
**Koin module and version:** [e.g]:koin-core:4.1.1`
Snippet or Sample project to help reproduce
WeirdIssueApp 3.zip