小编Ank*_*pta的帖子

收集服务中的流量

因此,我尝试在 onCreate() 中从前台服务 (LifecycleService) 中的流收集数据,但在第一次回调后,它没有提供新数据。

代码是:

    override fun onCreate() {
        super.onCreate()

        lifecycleScope.launchWhenStarted {
            repeatOnLifecycle(Lifecycle.State.STARTED) {
                observeCoinsPrices()
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

service android foreground-service kotlin-coroutines kotlin-flow

5
推荐指数
1
解决办法
1386
查看次数