- 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.
推薦閱讀
- Drupal 8 Blueprints
- 前端跨界開發指南:JavaScript工具庫原理解析與實戰
- Mastering OpenCV Android Application Programming
- Scala Design Patterns
- C和C++安全編碼(原書第2版)
- Object-Oriented JavaScript(Second Edition)
- Visual Basic程序設計習題解答與上機指導
- 深度學習:算法入門與Keras編程實踐
- Scala Reactive Programming
- Test-Driven Development with Django
- Scala Data Analysis Cookbook
- Practical Predictive Analytics
- Processing開發實戰
- 算法學習與應用從入門到精通
- ASP.NET 4權威指南