You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to inject view model with dynamic parameters in it's constructor to fragment via sharedViewModel and new instance of this view model is created instead of using the instance that was created by the activity. If i am not passing parameters to shared view model the app crashes with Could not create instance for [type:Factory,primary_type:'co.anyvision.abraxas.settings.padding.CameraPaddingViewModel']
To Reproduce
This is the view model module val cameraPaddingViewModelModule = module { viewModel { (padding: Padding) -> CameraPaddingViewModel(padding) } }
This is the creation of view model in the activity val viewModel: CameraPaddingViewModel by viewModel{ parametersOf(padding) }
now in fragment level:
if i try val viewModel: CameraPaddingViewModel by sharedViewModel(from = { activity!! })
the app crashes with: Could not create instance for [type:Factory,primary_type:'co.anyvision.abraxas.settings.padding.CameraPaddingViewModel']
if try with getSharedViewModel same crash happens. I can inject the view model to fragment by passing paramater as i did in the activity level but in that case koin inject new instance instead of the one i already injected to activity.
I am trying to inject view model with dynamic parameters in it's constructor to fragment via sharedViewModel and new instance of this view model is created instead of using the instance that was created by the activity. If i am not passing parameters to shared view model the app crashes with
Could not create instance for [type:Factory,primary_type:'co.anyvision.abraxas.settings.padding.CameraPaddingViewModel']
To Reproduce
This is the view model module
val cameraPaddingViewModelModule = module { viewModel { (padding: Padding) -> CameraPaddingViewModel(padding) } }
This is the creation of view model in the activity
val viewModel: CameraPaddingViewModel by viewModel{ parametersOf(padding) }
now in fragment level:
if i try
val viewModel: CameraPaddingViewModel by sharedViewModel(from = { activity!! })
the app crashes with:
Could not create instance for [type:Factory,primary_type:'co.anyvision.abraxas.settings.padding.CameraPaddingViewModel']
if try with getSharedViewModel same crash happens. I can inject the view model to fragment by passing paramater as i did in the activity level but in that case koin inject new instance instead of the one i already injected to activity.
Koin versions:
koin-android-2.0.1
koin-viewmodels-2.0.1
The text was updated successfully, but these errors were encountered: