Skip to content

Commit

Permalink
Destroy Presenter in onDestoy() for ActivityMviDelegate
Browse files Browse the repository at this point in the history
  • Loading branch information
sockeqwe committed Jan 15, 2017
1 parent 5573eb7 commit 79916eb
Showing 1 changed file with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ public ActivityMviDelegateImpl(@NonNull Activity activity,
*/
public ActivityMviDelegateImpl(@NonNull Activity activity,
@NonNull MviDelegateCallback<V, P> delegateCallback, boolean keepPresenterInstance) {

if (activity == null){
throw new NullPointerException("Activity is null");
}

if (delegateCallback == null) {
throw new NullPointerException("MvpDelegateCallback is null!");
}
Expand Down Expand Up @@ -177,28 +182,34 @@ private P createViewIdAndCreatePresenter() {
}
}

private boolean retainPresenterInstance(){
return keepPresenterInstance && activity.isChangingConfigurations();
}

@Override public void onStop() {
boolean retainPresenterInstance = keepPresenterInstance && activity.isChangingConfigurations();
boolean retainPresenterInstance = retainPresenterInstance();
presenter.detachView(retainPresenterInstance);
if (!retainPresenterInstance) {
presenterManager.removePresenterAndViewState(mosbyViewId, activity);
}

if (DEBUG) {
Log.d(DEBUG_TAG, "detached MvpView from Presenter. MvpView "
+ delegateCallback.getMvpView()
+ " Presenter: "
+ presenter);
Log.d(DEBUG_TAG, "Retaining presenter instance: "
+ Boolean.toString(retainPresenterInstance).toUpperCase()
+ " "
+ presenter);

}

presenterManager.cleanUp();
}

@Override public void onDestroy() {

// A little bit ugly, because presenter will be instantiated in onStart() and not in onCreate()
if (!retainPresenterInstance()) {
presenterManager.removePresenterAndViewState(mosbyViewId, activity);
Log.d(DEBUG_TAG, "Destroying Presenter permanently "
+ presenter);
}

presenterManager = null;
presenter = null;
activity = null;
Expand Down

0 comments on commit 79916eb

Please sign in to comment.