Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Presenter base class
public abstract class BasePresenter<V extends RemoteView> {
private WeakReference<V> view = null;
public final void attachView(V view) {
if (view == null) throw new NullPointerException("View must not be null");
if(this.view != null) detachView(this.view.get());
this.view = new WeakReference<V>(view);
public final void detachView(V view) {
if (view == null) throw new NullPointerException("Detached view must not be null");
this.view = null;
protected final boolean isViewAttached() {
return view != null;
protected final V getView() {
if (view == null) throw new NullPointerException("getView called when view is null. " +
"Make sure to setView(View) is called first!");
return view.get();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment