Where should the android service calls and calls to GoogleAPIClient be written while using MVP pattern in android?
Using dagger makes it easier to inject the Interactor on your Presenter. Try this link (https://github.com/spengilley/AndroidMVPService)
I'm trying to achieve it without dagger. But this seems violates the MVP architecture.
From the Activity, I created an instance of Interactor. Then create instance of Presenter with the Interactor as one of the parameter.
Activity
public class SomeActivity extends Activity implements SomeView { private SomePresenter presenter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); SomeInteractor interactor = new SomeInteractorImpl(SomeActivity.this); presenter = new SomePresenterImpl(interactor,this); } @Override protected void onStart() { super.onStart(); presenter.startServiceFunction(); }
Presenter
public interface SomePresenter { public void startServiceFunction();}
Presenter Implementation
public class SomePresenterImpl implements SomePresenter { private SomeInteractor interactor; private SomeView view; public SomePresenterImpl(SomeInteractor interactor,SomeView view){ this.interactor = interactor; this.view = view; } @Override public void startServiceFunction() { interactor.startServiceFunction(); }}
Interactor
public interface SomeInteractor { public void startServiceFunction();}
Interactor Implementation
public class SomeInteractorImpl implements SomeInteractor { private Context context; public SomeInteractorImpl(Context context) { this.context = context; } @Override public void startServiceFunction() { Intent intent = new Intent(context, SomeService.class); context.startService(intent); }}
I am also searching for your first question. However, I have the answer of the second question.
The answer is Dagger2. (http://google.github.io/dagger/) You can easily inject GoogleApiClient object by using Dagger2.