Skip to content

Instantly share code, notes, and snippets.

@IlyaGulya
Created December 19, 2019 16:55
Show Gist options
  • Save IlyaGulya/05360e9437721bf21c6c5f316dfe047c to your computer and use it in GitHub Desktop.
Save IlyaGulya/05360e9437721bf21c6c5f316dfe047c to your computer and use it in GitHub Desktop.
override fun onDestroy() {
super.onDestroy()
if (needCloseScope()) {
// Destroy this fragment with scope
Timber.d("Destroy UI scope: $fragmentScopeName")
Toothpick.closeScope(scope.name)
}
}
// This is android, baby!
private fun isRealRemoving(): Boolean =
(isRemoving && !instanceStateSaved) || // Because isRemoving == true for fragment in backstack on screen rotation
((parentFragment as? BaseFragment)?.isRealRemoving() ?: false)
// It will be valid only for 'onDestroy()' method
private fun needCloseScope(): Boolean =
when {
activity?.isChangingConfigurations == true -> false
activity?.isFinishing == true -> true
else -> isRealRemoving()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment