Bla*_*sor 11 mvp android design-patterns android-service android-googleapiclient
我试图通过引用此链接在我的android项目中实现MVP模式:https://github.com/jpotts18/android-mvp
我已成功实现了view/presenter/interactor类.我不清楚
service拨打电话代码?由于我无法在演示者或者交互器类中获取上下文,因此我无法将
service调用放在那里
GoogleApiClient课程?由于
GoogleApiClient还需要运行上下文,因此在没有上下文的情况下也无法在展示器或交互器内实现
小智 7
使用匕首可以更轻松地在Presenter上注入Interactor.试试这个链接(https://github.com/spengilley/AndroidMVPService)
我试图在没有匕首的情况下实现它.但这似乎违反了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();
}
Run Code Online (Sandbox Code Playgroud)
主持人
public interface SomePresenter {
public void startServiceFunction();
}
Run Code Online (Sandbox Code Playgroud)
演示者实施
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();
}
}
Run Code Online (Sandbox Code Playgroud)
交互器
public interface SomeInteractor {
public void startServiceFunction();
}
Run Code Online (Sandbox Code Playgroud)
交互式实施
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);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2669 次 |
| 最近记录: |