As launchWhenStarted and repeatOnLifecycle(STARTED) provide completely different functionality (launchWhenStarted suspends the execution of the coroutine, and repeatOnLifecycle cancels and restarts a new coroutine), if the names of the new APIs were similar (for example, using launchWhenever for the restarting APIs), developers could’ve got confused and even use them interchangeably without noticing.
source
什么时候使用哪个更简单的解释是什么?
最佳答案
launchWhenStarted
只是一次延迟。repeatOnLifecycle
创建一个挂起点,充当处理程序,每次生命周期进入提供状态时运行提供的 block ,并在低于它时取消它(因此对于 STARTED
它在停止时发生)。
关于android - launchWhenStarted 和 repeatOnLifecycle(STARTED) 收集流的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71113597/