如何修复此代码中的弃用警告?或者,还有其他选择吗?
runOnUiThread {
doAsync {
// room insert query
}
}
// anko Commons
implementation "org.jetbrains.anko:anko-commons:0.10.8"
如何修复此代码中的弃用警告?或者,还有其他选择吗?
runOnUiThread {
doAsync {
// room insert query
}
}
// anko Commons
implementation "org.jetbrains.anko:anko-commons:0.10.8"
TLDR:老实说,我强烈建议充分利用Kotlin.
由于我不知道您的确切目的Anko,因此我将非常笼统地回答。
Anko很棒,但现在是时候继续前进了......虽然有几种选择,但Kotlin它本身就是“最好”的选择Anko
您可以使用. _ _ Anko_ Kotlin's Extension functions(阅读更多)
像这样:
fun MutableList<Int>.swap(index1: Int, index2: Int) {
val tmp = this[index1] // 'this' corresponds to the list
this[index1] = this[index2]
this[index2] = tmp
}
val list = mutableListOf(1, 2, 3)
list.swap(0, 2) // 'this' inside 'swap()' will hold the value of 'list'
您可以使用最先进的异步编程库,名为Coroutinewhich Waaaaay faster than RxJava. (阅读更多)
fun main() = runBlocking { // this: CoroutineScope
launch { // launch a new coroutine and continue
delay(1000L) // non-blocking delay for 1 second (default time unit is ms)
println("World!") // print after delay
}
println("Hello") // main coroutine continues while a previous one is delayed
}
还有更多可以满足您的需求。
如果您有任何问题,请告诉我。