android kotlin 协程使用经验

1.    https://www.kotlincn.net/docs/reference/coroutines/cancellation-and-timeouts.html

  runBlocking 也是非常有用的,,,用在很多需要 立即运行,,不能挂起的场合

2.  
  阻塞线程

表达式内部

是否有返回值

并发执行
runBlocking 
true true false(串行)
withContext false true false
launch
false false false
asyc false true true

3.安卓的StrictMode模式似乎不识别 launch(Dispatchers.IO) 的线程切换
StrictMode: StrictMode policy violation: android.os.strictmode.NetworkViolation
需要使用 launch(newSingleThreadContext("xxxxThread"))

posted on 2020-11-20 15:49  caosiqiao  阅读(419)  评论(0编辑  收藏  举报

导航