Commit 662066ef authored by Konstantin Tskhovrebov's avatar Konstantin Tskhovrebov 🤖

Fix fragment scope life cycle.

Scope was destroyed for "don't keep activities" mode but presenter not.
parent 0ecd9edc
......@@ -74,20 +74,33 @@ abstract class BaseFragment : MvpAppCompatFragment() {
override fun onSaveInstanceState(outState: Bundle) {
outState.putString(STATE_SCOPE_NAME, fragmentScopeName)
outState.putBoolean(STATE_SCOPE_WAS_CLOSED, activity?.isChangingConfigurations == false)
instanceStateSaved = true
outState.putString(STATE_SCOPE_NAME, fragmentScopeName)
outState.putBoolean(STATE_SCOPE_WAS_CLOSED, needCloseScope()) //save it but will be used only if destroyed
override fun onDestroy() {
if (activity?.isChangingConfigurations == false) {
if (needCloseScope()) {
//destroy this fragment with scope
Timber.d("Destroy UI scope: $fragmentScopeName")
//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()
protected fun showProgressDialog(progress: Boolean) {
if (!isAdded || instanceStateSaved) return
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment