I am trying to Inject activity's view model and I want use it inside Dialog Fragment, how to inject it with Kodein? and use the view model which I've inject before in other activity or fragments.
I've try tutorial from medium here is the tutorial
https://proandroiddev.com/android-viewmodel-dependency-injection-with-kodein-249f80f083c9
I am trying to access injection result from activity's view model but when I try access some object inside the viewModel from Dialog Fragment the value is null not the same with activity's viewModel
// This is from Activity
private val viewModelFactory: TriplogisticViewModelFactory by instance()
private val viewModel: TriplogisticViewModel by lazy {
ViewModelProviders
.of(this@ContactDetailBottomSheetDialogFragment, viewModelFactory)
.get(TriplogisticViewModel::class.java)
}
Log.e("VIEWMODEL_ACTIVITY", viewModel.mode.get().toString) // result is SENDER_MODE
I am expecting when I access some object inside the dialog fragment's viewModel, I got same value as activity's viewModel
// This is from Dialog Fragment
private val viewModelFactory: TriplogisticViewModelFactory by instance()
private val viewModel: TriplogisticViewModel by lazy {
ViewModelProviders
.of(this@ContactDetailBottomSheetDialogFragment, viewModelFactory)
.get(TriplogisticViewModel::class.java)
}
I want same result as activity's viewModel object but I got null result
Log.e("VIEWMODEL_FRAGMENT", viewModel.mode.get().toString) // result is null