因此,我尝试在 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