The following Kotlin/Room database code runs fine, but I need to get off the main thread.
I've read all kinds of complex tutorials, but just a simple example (if that's possible) would really help!
@Composable
fun myApp(myContext: Context) {
val db = Room.databaseBuilder (
myContext,
AppDatabase::class.java,
"test.db")
.allowMainThreadQueries() // How to eliminate this line?
.createFromAsset("test.db")
.build()
val itemDAO = db.itemDAO()
var itemList = remember { mutableStateListOf( itemDAO.getAll() ) }
println("******************** Print Item List ********************")
for (i in 0 until itemList.size) {
itemList[i].listIterator().forEach { println(it.first_name + " " + it.last_name) }
}
}
Dispatcher.IOto move database operation off the main thread.