使用clearAllTables ()与RXJava,如下所示,以避免java.lang.IllegalStateException: Cannot access database on the main thread since it may potentially lock the UI for a long period of time.
fun Activity.emptyDatabase() {
// create a scope to access the database from a thread other than the main thread
val scope = CoroutineScope(Dispatchers.Default)
scope.launch {
SitukaDatabase.getInstance(this@emptyDatabase).clearAllTables()
}
}