1

如何修复此代码中的弃用警告?或者,还有其他选择吗?

   runOnUiThread {

        doAsync {
             // room insert query
        }
   }
// anko Commons
implementation "org.jetbrains.anko:anko-commons:0.10.8"
4

2 回答 2

3

TLDR:老实说,我强烈建议充分利用Kotlin.

由于我不知道您的确切目的Anko,因此我将非常笼统地回答。

Anko很棒,但现在是时候继续前进了......虽然有几种选择,但Kotlin它本身就是“最好”的选择Anko

  1. 可以使用. _ _ 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'
    
  2. 您可以使用最先进的异步编程库,名为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
     } 
    
  3. 还有更多可以满足您的需求。

如果您有任何问题,请告诉我。

于 2021-07-06T13:24:39.607 回答
0

正如他们在github上的弃用页面上所说,还有更多选择。至于他们提供两个库的公共资源,所有链接都在这里,请记住,其中一些库可以被弃用,因为该页面的上次更新是 2 年前。

于 2021-07-06T10:18:39.440 回答