In my application I am fetching data from an api and saving it in Room Database. Fetching data from api and showing it directly in adapter is working fine.
But in case of no internet connection I am fetching data from database using coroutines. Problem here is I get the data successfully from database but it's not getting updated in the adapter. I tried calling notifyDataSetChanged after fetching data but still it's not showing anything on UI.
Also I have noticed a weird thing is that if I run the app in debug mode and go through all the code , it does shows list in the adapter when debugging is stopped .
Below is the code for fetching data from database and adding it in adapter.
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
if (isInternetAvailable()) {
if (jobsList.size == 0) {
getJobs()
}
}else{
GlobalScope.launch {
jobsList.addAll(dataBaHelperImpl.getJobs())
}
jobsViewModel.setJobsList(jobsList)
}
}
ViewModel setJobList method
fun setJobsList(orderList: ArrayList<Jobs>){
jobsAdapter.setItems(orderList)
jobsAdapter.notifyDataSetChanged()
}