Answer the question
In order to leave comments, you need to log in
How to pass AppCompatActivity to module?
Hello!
I use Dagger 2 in my project. I have several modules in my project.
And I have a BaseActivityModule which is connected to each Activity module.
How to get AppCompatActivity in BaseActivityModule.
When compiling the project I get the following error
error: [Dagger/MissingBinding] [dagger.android.AndroidInjector.inject(T)] android.app.AlertDialog cannot be provided without an @Inject constructor or an @Provides-annotated method.
public abstract interface AppComponent {
^
android.app.AlertDialog is injected at
com.example.laptop.daggerexample.ui.main.view.MainActivity.alertDialog
com.example.laptop.daggerexample.ui.main.view.MainActivity is injected at
dagger.android.AndroidInjector.inject(T)
component path: com.example.laptop.daggerexample.di.component.AppComponent ? com.example.laptop.daggerexample.di.builder.ActivityBuilder_BindMainActivity.MainActivitySubcomponent
@Module
abstract class ActivityBuilder {
@ContributesAndroidInjector(modules = [(MainActivityModule::class)])
abstract fun bindMainActivity(): MainActivity
}
@Module
abstract class AppModule{
@Provides
@Singleton
fun provideContext(application: Application): Context = application
}
@Module
class BaseActivityModule {
@Provides
fun provideAlertDialog(activity: AppCompatActivity)= AlertDialog.Builder(activity).create()
}
@Module(includes = [(BaseActivityModule::class)])
class MainActivityModule {
@Provides
fun provideMainMVPView(activity: MainActivity): MainMVPView = activity
@Provides
fun provideMainMVPPresenter(presenter: MainPresenter<MainMVPView>): MainMVPPresenter<MainMVPView> = presenter
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question