- Learning Concurrency in Kotlin
- Miguel Angel Castiblanco Torres
- 73字
- 2021-08-05 10:46:49
Using Android's UI coroutine dispatcher
With this done, we can now use the dispatcher in the same way we use any other, for example:
launch(dispatcher) {
val headlines = fetchRssHeadlines()
val newsCount = findViewById<TextView>(R.id.newsCount)
launch(UI) {
newsCount.text = "Found ${headlines.size} News"
}
}
The UI dispatcher comes from the library we just added, kotlinx-coroutines-android.
Executing the code at this point will work. The quantity of news will be correctly displayed on the application.
推薦閱讀
- Practical Data Analysis Cookbook
- Mastering JavaScript Functional Programming
- Visual C++數字圖像模式識別技術詳解
- Oracle 12c中文版數據庫管理、應用與開發實踐教程 (清華電腦學堂)
- Ray分布式機器學習:利用Ray進行大模型的數據處理、訓練、推理和部署
- 名師講壇:Java微服務架構實戰(SpringBoot+SpringCloud+Docker+RabbitMQ)
- Mastering KnockoutJS
- bbPress Complete
- Java系統化項目開發教程
- Android玩家必備
- Android驅動開發權威指南
- Red Hat Enterprise Linux Troubleshooting Guide
- Webpack實戰:入門、進階與調優(第2版)
- Android Development Tools for Eclipse
- 深度學習程序設計實戰