What do i use now that Anko is deprecated?

3.5k views Asked by At

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"
2

There are 2 answers

0
TheForgottenOne On

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.

0
minchaej On

TLDR: 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

  1. You could make all the general helper methods from Anko using Kotlin's Extension functions. (read more)

    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'
    
  2. You could use the state-of-the-art async programming library called Coroutine which Waaaaay faster than RxJava. (read more)

    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
     } 
    
  3. And much more to fulfill your needs.

Let me know if you have any questions.