Open Tweeel opened 1 month ago
Have you enabled "Don't keep activities" in developer settings on your phone?
No, and I just found the problem. Initially, I was passing the viewModels directly to the screens. I created a viewModelFactory to avoid the need to pass it each time, to facilitate testing later:
class ViewModelFactory : KoinComponent {
inline fun <reified T : ScreenModel, reified P> getViewModel(parameter: P): T {
val viewModel: T by inject { parametersOf(parameter) }
return viewModel
}
inline fun <reified T: ScreenModel> getViewModel(): T {
val viewModel: T by inject()
return viewModel
}
}
I noticed from another issue that removing "then" and calling the viewModel using the getScreenModel
function from the screen content should fix the problem, and it actually did in my case. But it would still be nice if we could directly pass the viewModel in the parameter, as I mentioned earlier, to make testing easier.
I was passing the viewModels directly to the screens
Haven't worked with Koin, but have you checked documentation? it looks pretty straightforward
I am working on a KMM project and facing an issue with my Android app. The iOS app works perfectly, but the Android app restarts and recreates the whole activity each time I minimize it.