3

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"
Bolt UIX
  • 5,988
  • 6
  • 31
  • 58
  • 1
    And what do you want to do? Run insert query in background thread and return to UI? Then you should use coroutines or RxJava. – CoolMind Jul 06 '21 at 09:48
  • 1
    thank u, i have plan to use coroutines & also going to remove anko lib in my project – Bolt UIX Jul 06 '21 at 10:09

2 Answers2

4

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.

minchaej
  • 1,294
  • 1
  • 7
  • 14
0

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.