Fix coroutine error: Cannot access database on the main thread // Android Dev Diary

As I was running a test for a ViewModel function, I encountered the following error: […] Main Thread @coroutine java.lang.IllegalStateException: Cannot access database on the main thread since it may potentially lock the UI for a long period of time. I think it may be caused by the viewModelScope from viewModelScope.launch {} being used by […]

Read More

A working shared ViewModel between parent and child Fragments //Android Kotlin Dev Diary

I initially had a problem with the shared ViewModel because the child fragments were creating a new instance from the one held by the parent fragment. The ViewModel instantiations below work for me: CreateLogFragment.kt (parent)

CreateLogFoodFragment.kt (child)

CreateLogNotesFragment.kt (another child)

by activityViewModels turned things around!

Read More