android - Anko 已被弃用,我现在用什么?
问题描述
如何修复此代码中的弃用警告?或者,还有其他选择吗?
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'
您可以使用最先进的异步编程库,名为
Coroutine
which Waaaaay faster thanRxJava
. (阅读更多)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 }
还有更多可以满足您的需求。
如果您有任何问题,请告诉我。
推荐阅读
- python - python:object()不带参数错误
- python - 布尔切片交换 numpy 数组的维度
- javascript - 将 nodetext 附加到 svg 元素
- spring - Spring Boot 页面刷新有一些 404 请求
- android - 在 BottomNavigationView 中禁用 tooltipText
- ruby-on-rails - 使用 ActiveRecord 在哪里找不到记录时如何失败?
- android - 无法在 Google Play 管理中心开启定时发布模式
- sql - Oracle 内联视图列别名仅在加入表之前有效,而在加入表时无效
- php - 回调函数中php打开和关闭标签的奇怪用法
- python-3.x - 无法导入模块“lambda_function”:没有名为“pandas”的模块