View层的代码
public abstract class BaseMvpActivity<V,T extends BasePresenter<V>> extends Activity {
public abstract T initPresenter();
public T presnter ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
presnter = initPresenter();
}
@Override
protected void onResume() {
super.onResume();
presnter.attach((V) this);
}
@Override
protected void onDestroy() {
super.onDestroy();
presnter.detach();
}
P层
public class BasePresenter<V> {
public V view ;
public void attach(V v){
this.view = v;
}
public void detach(){
this.view = null;
}
}