gpt4 book ai didi

android - launchWhenStarted 和 repeatOnLifecycle(STARTED) 收集流的区别

转载 作者:行者123 更新时间:2023-12-04 23:41:37 47 4
gpt4 key购买 nike

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/

47 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com