Created
November 26, 2016 10:15
-
-
Save xanderblinov/c2fa5c2250750c7e0b5356de56596153 to your computer and use it in GitHub Desktop.
How to prevent Moxy's delegate onDestroy call of fragment in backstack while configuration changing.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void onDestroy() { | |
super.onDestroy(); | |
boolean anyParentIsRemoving = false; | |
for (Fragment parent = this.getParentFragment(); !anyParentIsRemoving && parent != null; | |
parent = parent.getParentFragment()) { | |
anyParentIsRemoving = parent.isRemoving(); | |
} | |
boolean callOnDestroy = false; | |
if (this.isRemoving() || anyParentIsRemoving || this.getActivity().isFinishing()) { | |
callOnDestroy = true; | |
} | |
// prevent removing fragments from back stack | |
for (int i = 0; i < getFragmentManager().getBackStackEntryCount(); i++) { | |
if (TextUtils.equals(getFragmentManager().getBackStackEntryAt(i).getName(), getTag())) { | |
callOnDestroy = false; | |
break; | |
} | |
} | |
if(callOnDestroy){ | |
this.getMvpDelegate().onDestroy(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment