Reputation: 7012
How do I fix the deprecation warning in this code? Alternatively, are there any other options for doing this?
runOnUiThread {
doAsync {
// room insert query
}
}
// anko Commons
implementation "org.jetbrains.anko:anko-commons:0.10.8"
Upvotes: 5
Views: 5475
Reputation: 1814
TL;DR: I would honestly highly recommend making full use of Kotlin.
Since I do not know your exact purpose of Anko, I will answer very generally.
Anko was great, but now it is time to move on... Although there are several alternatives out there, Kotlin itself is the "best" alternative to Anko.
You could make all the general helper methods from Anko using Kotlin's Extension functions. Like this:
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'
You could use the state-of-the-art async programming library called Coroutine which is way 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
}
Upvotes: 4
Reputation: 49
As they say on their deprecation page on github, there are more alternatives. As for commons they provide two libs, all the links are here, keep in mind that some of these libs can be deprecated since last update of that page was 2 years ago.
Upvotes: -1