【发布时间】:2019-03-20 09:31:31
【问题描述】:
我正在尝试使用 MVP 模式检查互联网连接。为此,我有一个类MyAppUtil,它在其构造函数中采用Context。这是我的 MVP 模型类,我正在使用 MyAppUtil.checkConnection(context) 检查互联网连接:
public class MainActivityInterectorImpl implements MainActivityContract.IInterector{
Context context;
MainActivityInterectorImpl(Context context) {
this.context = context;
}
@Override
public void getData(OnFinishedListener onFinishedListener) {
boolean result = MyAppUtil.checkConnection(context);
if (result == true) {
onFinishedListener.onSuccess();
} else {
onFinishedListener.onFailure();
}
}
}
在 VIEW 中,我正在通过以下方式初始化演示者:
presenter = new MainActivityPresenterImpl(this, new MainActivityInterectorImpl(this));
如您所见,我在 MVP 模型中使用 Context。这在 MVP 模式中可以吗?有更好的方法吗?
【问题讨论】:
标签: android android-context android-mvp