I follow this guide for making sub components for my Android application. Here I defined one sub component named LoginComponent
used for LoginActivity:
@Subcomponent(modules = LoginModule.class)
public interface LoginComponent {
void inject(LoginActivity activity);
@Subcomponent.Builder
interface Builder {
Builder requestModule(LoginModule module);
LoginComponent build();
}
}
@Module
public class LoginModule {
@Provides
LoginManager provideLoginManager(LoginManagerImpl manager) {
return manager;
}
@Provides
LoginView provideLoginView(LoginViewImpl view) {
return view;
}
@Provides
LoginPresenter loginPresenter(LoginView view, LoginManager manager) {
return new LoginPresenterImpl(view, manager);
}
}
I define this sub component inside another component:
@Module(subcomponents = LoginComponent.class)
public interface AppModule {
}
@Singleton
@Component(modules = {
AppModule.class
})
public interface AppComponent {
}
Here is my LoginActivity:
public class LoginActivity extends AppCompatActivity {
@Inject LoginPresenter presenter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
}
}
My question is:
- purpose of
@Subcomponent.Builder
. I don't understand this point, because all modules in this component has been defined on@Subcomponent
annotation. Why should we duplicate again. - how can I injected LoginPresenter on above activity.
Thanks