BottomNavigationView back button behavior should work like the Youtube App but crashes
BottomNavigationView back button behavior should work like the Youtube App but crashes Steps to reproduce: BottomNavigationView Replace MainActivity with this: class MainActivity : AppCompatActivity() { private var fragmentIds = ArrayList<Int>() val fragmentA: FragmentA = FragmentA() private val fragmentB = FragmentB() private val fragmentC = FragmentC() private fun getFragment(fragmentId: Int): Fragment { when (fragmentId) { R.id.navigation_home -> { return fragmentA } R.id.navigation_dashboard -> { return fragmentB } R.id.navigation_notifications -> { return fragmentC } } return fragmentA } private fun updateView(fragmentId: Int) { var exists = false fragmentIds .filter { it == fragmentId } .forEach { exists = true } if (exists) { fragmentIds.remove(fragmentId) showTabWithoutAddingToBackStack(getFragment(fragmentId)) } ...