diff --git a/mvp/src/main/java/com/hannesdorfmann/mosby3/mvp/delegate/ViewGroupMvpDelegateImpl.java b/mvp/src/main/java/com/hannesdorfmann/mosby3/mvp/delegate/ViewGroupMvpDelegateImpl.java index 2dec45c8..20ca480b 100644 --- a/mvp/src/main/java/com/hannesdorfmann/mosby3/mvp/delegate/ViewGroupMvpDelegateImpl.java +++ b/mvp/src/main/java/com/hannesdorfmann/mosby3/mvp/delegate/ViewGroupMvpDelegateImpl.java @@ -63,7 +63,7 @@ public class ViewGroupMvpDelegateImpl delegateCallback, @@ -231,10 +231,10 @@ public void onRestoreInstanceState(Parcelable state) { keepPresenterDuringScreenOrientationChange, activity); if (destroyPermanently) { - destroyPresenterIfnotDoneYet(); + destroyPresenterIfNotDoneYet(); } else if (!activity.isChangingConfigurations()) { // View removed manually from screen - destroyPresenterIfnotDoneYet(); + destroyPresenterIfNotDoneYet(); } } // else --> see onActivityDestroyed() } @@ -242,7 +242,7 @@ public void onRestoreInstanceState(Parcelable state) { @Override public void onActivityDestroyed(Activity activity) { if (activity == this.activity) { - // The hosting activity of this view has been destroyed, so time to destoryed the presenter too? + // The hosting activity of this view has been destroyed, so time to destroy the presenter too? activity.getApplication().unregisterActivityLifecycleCallbacks(this); checkedActivityFinishing = true; @@ -253,7 +253,7 @@ public void onRestoreInstanceState(Parcelable state) { if (destroyedPermanently) { // Whole activity will be destroyed detachPresenterIfNotDoneYet(); - destroyPresenterIfnotDoneYet(); + destroyPresenterIfNotDoneYet(); } } @@ -277,11 +277,13 @@ public void onRestoreInstanceState(Parcelable state) { @Override public void onActivitySaveInstanceState(Activity activity, Bundle outState) { } - private void destroyPresenterIfnotDoneYet() { - if (!presenterDestroeyed) { + private void destroyPresenterIfNotDoneYet() { + if (!presenterDestroyed) { P presenter = delegateCallback.getPresenter(); - presenter.destroy(); - presenterDestroeyed = true; + if (presenter != null) { + presenter.destroy(); + } + presenterDestroyed = true; activity.getApplication().unregisterActivityLifecycleCallbacks(this); if (DEBUG) { Log.d(DEBUG_TAG, "Presenter destroyed: " + presenter); @@ -298,7 +300,9 @@ private void destroyPresenterIfnotDoneYet() { private void detachPresenterIfNotDoneYet() { if (!presenterDetached) { P presenter = delegateCallback.getPresenter(); - presenter.detachView(); + if (presenter != null) { + presenter.detachView(); + } presenterDetached = true; if (DEBUG) { Log.d(DEBUG_TAG,