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
More optimized version There is no need in multiple call of commit so lets call it one time at the end
supportFragmentManager.fragments.let { if (it.isNotEmpty()) { supportFragmentManager.beginTransaction().apply { for (fragment in it) { remove(fragment) } commit() } } }