- 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.
推薦閱讀
- DB2 V9權威指南
- OpenStack Cloud Computing Cookbook(Third Edition)
- Python快樂編程:人工智能深度學習基礎
- Rust編程:入門、實戰與進階
- 算法零基礎一本通(Python版)
- Access 數據庫應用教程
- Ext JS Data-driven Application Design
- 程序員考試案例梳理、真題透解與強化訓練
- Building an RPG with Unity 2018
- MATLAB for Machine Learning
- UVM實戰
- AIRIOT物聯網平臺開發框架應用與實戰
- CodeIgniter Web Application Blueprints
- TypeScript全棧開發
- 區塊鏈:技術與場景