I haven\'t found a simple way to get all currently active (visible, currently in Resumed state) Fragments in an Activity. Is it possible without custom bookkeeping in my Act
Here is a recursive solution in Kotlin. Given the top-most fragments of an activity, returns all the descendant fragments.
fun recursiveGetFragments(parents: List): List {
val result = parents.toMutableList()
for(root in parents) {
if (root.isVisible) {
result.addAll(recursiveGetFragments(root.childFragmentManager.fragments))
}
}
return result
}
It is used as:
val fragmentList = recursiveGetFragments(supportFragmentManager.fragments)