Skip to content
Snippets Groups Projects
Unverified Commit 5f4524c6 authored by Matthias Urhahn's avatar Matthias Urhahn Committed by GitHub
Browse files

Prevent IllegalStateException when orphaned Fragments try to popBackStack()...

Prevent IllegalStateException when orphaned Fragments try to popBackStack() (EXPOSUREAPP-4430) #1987

* Prevent IllegalStateException if a fragment that's not added to an Activity tries to popBackStack()

* Typo
parent 865b99e3
No related branches found
No related tags found
No related merge requests found
......@@ -4,7 +4,16 @@ import androidx.fragment.app.Fragment
import androidx.navigation.NavDirections
import androidx.navigation.fragment.findNavController
import de.rki.coronawarnapp.ui.doNavigate
import timber.log.Timber
fun Fragment.doNavigate(direction: NavDirections) = findNavController().doNavigate(direction)
fun Fragment.popBackStack() = findNavController().popBackStack()
fun Fragment.popBackStack(): Boolean {
if (!isAdded) {
IllegalStateException("Fragment is not added").also {
Timber.w(it, "Trying to pop backstack on Fragment that isn't added to an Activity.")
}
return false
}
return findNavController().popBackStack()
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment