kotlin协程启动方式
![](https://img2022.cnblogs.com/blog/1619947/202207/1619947-20220711144255274-175096547.png)
* rememberCoroutineScope
具体使用请看将 Kotlin 协程与生命周期感知型组件一起使用
例
private val mainScope:CoroutineScope = MainScope() override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) mainScope.launch(Dispatchers.Main) { withContext(Dispatchers.IO){ } } } override fun onDestroy() { mainScope.cancel() super.onDestroy() }