Hello! I'm having trouble getting a shared view m...
# koin
m
Hello! I'm having trouble getting a shared view model instance. VM is defined as
Copy code
module = {        viewModel { SharedViewModel(
            SearchProductsUseCase())
 }
    }
In my activity (Java; unfortunetly it needs to remain java right now.)
Copy code
SharedViewModel sharedViewModel = get(SharedViewModel.class);
In my fragment
Copy code
private val sharedViewModel: SharedViewModel by activityViewModel<SharedViewModel>()
But my logs show..
Copy code
activity VM INSTANCE: com.package.SharedViewModel@8e410b3
frag VM INTANCE: com.package.SharedViewModel@5d570c3
Why am I getting 2 different instances? Does it have to do with java class?
a
yes I believe the java access is not good
SharedViewModel sharedViewModel = get(SharedViewModel.class);
you need to use
koin-android-compat
for Java
image.png
use
viewModel(this,SharedViewModel.class)
thank you color 1