I'm using Dagger2 for DI in android app,
I want inject viewModel in a fragment by AndroidInjector
and have this two line :
AndroidInjection.inject(this)
viewModel = ViewModelProviders.of(this, viewModelFactory).get(ProductDetailViewModel::class.java)
When my fragment extends androidx.fragment.app.Fragment
shows this error:
- the first line uses deprecated
android.support.v4.app.Fragment
- but second uses
android.app.Fragment
now I don't know my fragment should extends which one!
I get this error when choose one of them :
None of the following functions can be called with the arguments supplied:
public open fun inject(activity: Activity!): Unit defined in dagger.android.AndroidInjection
public open fun inject(fragment: Fragment!): Unit defined in dagger.android.AndroidInjection
public open fun inject(service: Service!): Unit defined in dagger.android.AndroidInjection
public open fun inject(contentProvider: ContentProvider!): Unit defined in dagger.android.AndroidInjection