Presenter基类

public abstract class BasePresenter {
    protected Reference mViewRef;//View接口类型弱引用

    public void attachView(T view) {
        mViewRef = new WeakReference(view); //建立关联
    }

    protected T getView() {
        return mViewRef.get();//获取View
    }

    public boolean isViewAttached() {//判断是否与View建立了关联
        return mViewRef != null && mViewRef.get() != null;
    }

    public void detachView() {//解除关联
        if (mViewRef != null) {
            mViewRef.clear();
            mViewRef = null;
        }
    }
}

你可能感兴趣的:(Andorid工具封装)