Fragment Transaction Not Committing in Android Studio with Navigation Component
Could someone explain After trying multiple solutions online, I still can't figure this out... I'm confused about I'm experiencing an issue with fragment transactions not committing as expected while using the Navigation Component in my Android app. When I attempt to navigate between fragments using the `navController`, I am getting a `IllegalStateException` with the message: "Can not perform this action after onSaveInstanceState". This usually happens when I'm trying to navigate after the activity state has been saved. I have a simple setup where I'm using a BottomNavigationView to switch between fragments. Hereβs the relevant part of my `MainActivity`: ```kotlin class MainActivity : AppCompatActivity() { private lateinit var navController: NavController override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) val navHostFragment = supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as NavHostFragment navController = navHostFragment.navController bottomNavigationView.setOnNavigationItemSelectedListener { menuItem -> when (menuItem.itemId) { R.id.fragmentA -> { navController.navigate(R.id.fragmentA) true } R.id.fragmentB -> { navController.navigate(R.id.fragmentB) true } else -> false } } } } ``` I've verified that the navigation graph is properly set up and I have the necessary fragments declared. However, the issue arises particularly when I try to navigate after a configuration change, like an orientation change. I've tried wrapping the navigation call in a `if (savedInstanceState == null)` condition, but it doesn't seem to help. I also checked for instances where I might be calling navigation in `onPause()` or `onStop()`, but I couldn't find anything. I would greatly appreciate any guidance on how to resolve this issue and avoid the `IllegalStateException`. Is there a best practice for handling fragment transactions that involve the Navigation Component, especially after configuration changes? I'm open to any suggestions. The stack includes Kotlin and several other technologies. This is happening in both development and production on macOS.