'Room DB ANR Input dispatching timed out

I am doing a db get operation for my cart page which has multiple tables. I have mapper class which has all the relations with all the tables. I have used coroutines also to fetch the data :

lifecycleScope.launch(Dispatchers.IO) {
    val brandProdInfo = viewModel.getCartBrandAndProductsInfo()
    launch(Dispatchers.Main) {
        brandProdInfo.observe(viewLifecycleOwner, Observer { 
            productContainer: CartProductContainer?-> //Display data on UI 
        }
    }
}

I am having a method in viewmodel to get the data which I have called inside couroutine lifecyclescope IO Dispatcher and returned the result in the Main thread inside Main Dispatcher. But still the ANR occurs. Can someone provide me with a better solution to stop this ANR.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source