Is there a way to remove all fragments which already added the specific view with its view id?
For example I want to remove all fragments which is added R.id.fragmentcon
In case someone is looking for a code in Kotlin:
private fun clearFragmentsFromContainer() {
val fragments = supportFragmentManager.fragments
if (fragments != null) {
for (fragment in fragments) {
supportFragmentManager.beginTransaction().remove(fragment).commit()
}
}
//Remove all the previous fragments in back stack
supportFragmentManager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE)
}