Good question!
Craig Russell
1

Can you please let me know how to use Dagger when instantiating Presenter with injected parameters in the attachPresenter()? In my activity class, I am doing,

@Inject PlacesListPresenter presenter;
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
((BaseApplication) getApplication()).getApplicationComponent().inject(this);
attachPresenter();
// ...
}
private void attachPresenter() {
presenter = (PlacesListPresenter) getLastCustomNonConfigurationInstance();
if (presenter == null) {
presenter = new PlacesListPresenter(param1, param2);
}
presenter.setView(this);
}

The param1 and param2 parameters are placeholders that are injected via constructor in the presenter class only.

@Inject
public PlacesListPresenter(PlacesListUseCaseImpl placesListUseCase, DatabaseManager databaseManager) {...}

I don’t want to inject the usecase and database manger in the activity class in order to replace the params.

Basically, my question is how to replace the creating new Presenter(x,y) by using dagger injection @Inject presenter.

Show your support

Clapping shows how much you appreciated Prabin Timsina’s story.