Unexpected UI Freezing on RecyclerView Item Click in Android 14 with Navigation Component
I'm integrating two systems and I'm encountering a frustrating issue where the UI freezes for a noticeable duration when I click on an item in a `RecyclerView`. This happens only when using the Navigation Component in Android 14. I have set up my `RecyclerView` with a custom adapter that uses a listener interface to handle item clicks. Below is the relevant code snippet for the click listener setup: ```kotlin class MyAdapter(private val items: List<MyItem>, private val listener: OnItemClickListener) : RecyclerView.Adapter<MyAdapter.MyViewHolder>() { interface OnItemClickListener { fun onItemClick(item: MyItem) } inner class MyViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { init { itemView.setOnClickListener { listener.onItemClick(items[adapterPosition]) } } } override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder { val view = LayoutInflater.from(parent.context).inflate(R.layout.item_view, parent, false) return MyViewHolder(view) } override fun onBindViewHolder(holder: MyViewHolder, position: Int) { // Bind data to views } override fun getItemCount() = items.size } ``` In the `onItemClick` method, I am navigating to a new fragment using `findNavController()`, which seems to be the cause of the freeze. Here’s how I’m navigating: ```kotlin val action = MyFragmentDirections.actionMyFragmentToDetailFragment(selectedItem) findNavController().navigate(action) ``` I’ve noticed the freeze lasts for about 2-3 seconds before the new fragment loads, which is unacceptable for a good user experience. I’ve tried running the navigation action inside a `CoroutineScope` and adding animations, but the problem persists. Also, I ensured that no heavy processing is done on the UI thread during the click event. Here’s what I’ve attempted: 1. Used `postDelayed` to mitigate the freezing, but it only masks the problem rather than solving it. 2. Verified that no blocking I/O operations are happening during navigation. 3. Monitored logs using StrictMode for potential issues, but nothing significant appeared. The XML layout for the `RecyclerView` and the item looks fine, and I’ve also checked that there are no layout inflation issues. Is there a pattern or best practice I might be overlooking when navigating between fragments that can help avoid this UI freeze? This is my first time working with Kotlin LTS. Hoping someone can shed some light on this.