【发布时间】:2022-06-24 06:05:13
【问题描述】:
【问题讨论】:
-
launchWhenStarted suspends the execution of the coroutine, and repeatOnLifecycle cancels and restarts a new coroutine这就是区别。如果您有一个使用lauchWhen...启动的正在运行的协程并且生命周期低于该级别,则协程将被挂起(但仍会处于活动状态,因此取决于它所做的其他事情,您可能会在不需要的事情上浪费资源)。较新的repeatOn...更“聪明”,因为它可以取消协程并在需要时启动新的协程。看到这一点的最简单方法是自己尝试。
标签: android kotlin kotlin-flow