官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 邵阳县| 西宁市| 泊头市| 泾源县| 奈曼旗| 彰武县| 梓潼县| 会泽县| 临桂县| 水城县| 雅安市| 修文县| 开平市| 新余市| 东乌珠穆沁旗| 神农架林区| 浦城县| 静宁县| 枝江市| 睢宁县| 曲阳县| 安多县| 临江市| 马关县| 平定县| 金乡县| 珠海市| 巴彦淖尔市| 武山县| 江永县| 攀枝花市| 青田县| 汝南县| 工布江达县| 东城区| 霍州市| 长海县| 石林| 厦门市| 毕节市| 贡觉县|