Skip to content Skip to sidebar Skip to footer

Referencing The Activity Inside Its Module

How do I use the new AndroidInjector.inject and still be able to provide an Activity instance inside an Activity Module? The Dagger docs don`t make it clear how to archive this. T

Solution 1:

Check Dagger 2 Github issue 615

The instance of your Activity is automatically provided, just pass it as a parameter in your module methods.

Example:

@Provides@ActivityScope
public providePresenter(ActivityA activity) {
    returnnewPresenterA(activity);
}

You'll now be able to abstract simple modules. Your presenter can be constructor injected too.

This actually cutout a lot of code from all my modules.

Post a Comment for "Referencing The Activity Inside Its Module"