Why is my state not being saved in SavedStateHandl...
# koin
s
Why is my state not being saved in SavedStateHandle when injecting with koin?
Copy code
val homeViewmodelModule = module {
    viewModel { (handle: SavedStateHandle) -> HomeViewmodel(handle, get()) }
}

class HomeViewmodel(
    handle: SavedStateHandle,
    private val datastore: DataStore<Preferences>,
) : ViewModel(), KoinComponent {

private var _newState: String by handle.saved(
    key = "new_state",
    init = { "original" }
)
I set the state to _newState = "new state" send the app to the background, kill process and when restarting the value is the original
e
How do you kill it?
Try next - enable dev options, set “Don’t keep activities”. Open app, put in background.
When you kill app from recents - there is no chance OS gives app time to store things
s
Kill process in the device processes in AS. It should work, as it does in other projects. Something is not right with koin it the config.
e
Ah oke
Then I’m wrong
Maybe try to remove
handle
as builder parameter and just use
get
?
viewModelOf(::HomeViewModel)
s
This is in kotlin multiplatform project. Also tried using get() and didn't work.
e
Oke, then I’m silent, let’s wait for experienced guys
s
Ok. Thanks.
e