我已经成功实现了视图/演示者/交互者类.我不清楚
>哪里可以把服务电话代码?
Since i cannot get the context insIDe the presenter or interactor
class,I am not able to put theservice
call there
>在哪里实现Googleapiclient类?
解决方法 使用匕首可以更容易地在演示者上注入Interactor.尝试此链接( https://github.com/spengilley/AndroidMVPService)Since
Googleapiclient
also requires context to run,it also cannot be
implemented insIDe the presenter or interactor without a context
我试图实现它没有匕首.但这似乎违反了MVP架构.
从Activity开始,我创建了一个Interactor实例.然后使用Interactor创建Presenter的实例作为参数之一.
活动
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(); }
主持人
public interface SomePresenter { public voID startServiceFunction();}
演示者实现
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(); }}
交互器
public interface SomeInteractor { public voID startServiceFunction();}
互动实现
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); }}总结
以上是内存溢出为你收集整理的在Android中使用MVP模式时,应该写哪些Android服务调用和调用GoogleAPIClient?全部内容,希望文章能够帮你解决在Android中使用MVP模式时,应该写哪些Android服务调用和调用GoogleAPIClient?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)