I would like to use MVP with dagger in my project. In view I have this method and into this method I will pass some object to the presenter:
@Override
public void onLogin(User user, Cookie cookie, UUID sessionId, List<Permission> permissions) {
super.onLogin(user, cookie, sessionId, permissions);
presenter.onLogin(user, cookie, sessionId, permissions);
}
Here is my presenter:
public class Presenter implements ILogin.LoginPresenter{
private Context context;
@Inject
public Presenter(Context context) {
this.context = context;
}
@Override
public void onLogin(User user, Cookie cookie, UUID sessionId, List<Permission> permissions) {
Intent intent = new Intent(context,MainActivity.class);///?
Bundle bundle = new Bundle();///?
bundle.putString("USER", user.getUserName());
intent.putExtras(bundle);
context.startActivity(intent);
}
I have nothing in module :
@Module
public class LoginModule {
}
My questions:
Is it true that I am creating new object (
IntentandBundle) in the presenter when I am using dagger?How could I use dagger to my scenario? That's mean create new instance of intent and bundle in module class?
The point of MVP pattern is to separate business logic from its view. It's a common good practice not to have any android framework related code in your presenter (here your presenter depends on
Context,IntentandBundlefrom the android framework).In your case, you should not create your
IntentandBundlein your presenter since it belongs to your view (MainActivity).Your
onLoginfunction could look like this:where
viewis an interface implemented by yourMainActivityand injected in your presenter.