Unexpected UI Lag When Navigating Between Fragments with BottomNavigationView on Android 14
Quick question that's been bugging me - I'm experiencing important UI lag when navigating between fragments using a BottomNavigationView on Android 14. This scenario arises particularly when the fragments contain complex layouts with multiple ViewModels. I've set up everything according to the guidelines, but the transition appears to freeze for a noticeable second before displaying the new fragment. I've tried using the `FragmentTransaction` to replace fragments with animations, and I've ensured that the navigation component is up to date. Here's the relevant code snippet: ```kotlin val navController = findNavController(R.id.nav_host_fragment) navController.addOnDestinationChangedListener { controller, destination, arguments -> // Handle fragment transition logic here } bottomNavigationView.setOnNavigationItemSelectedListener { item -> when (item.itemId) { R.id.nav_home -> { navController.navigate(R.id.homeFragment) } R.id.nav_dashboard -> { navController.navigate(R.id.dashboardFragment) } R.id.nav_notifications -> { navController.navigate(R.id.notificationsFragment) } } true } ``` The lag is especially noticeable when switching to the `DashboardFragment`, which is populated with multiple API calls to load data. I’ve implemented `ViewModels` scoped to each fragment, and I use `LiveData` to observe data changes, but it seems like the UI thread is getting blocked somewhere. I've also tried profiling the app using Android Profiler, but wasn’t able to pinpoint the scenario. When I look at the logs, I don't see any specific behavior messages, but I do get warnings about the UI thread being busy. Does anyone have insights on optimizing fragment transitions or handling heavy data fetching without causing UI jank? Any advice or best practices would be greatly appreciated! My development environment is macOS. What am I doing wrong? This issue appeared after updating to Kotlin 3.9.