Are there any coroutine bindings for `Service` in ...
# coroutines
z
Are there any coroutine bindings for
Service
in Android? We’re currently using
override fun onHandleWork(intent: Intent)
in a
JobIntentService
and I was wondering if there was a more idiomatic way to make that function Coroutine friendly, as opposed to using
runBlocking { }
in there
found this https://gist.github.com/cbeyls/e7f874a480934d2a802873f8f8d91549 dunno if you found a better solution for this @louiscad
l
@zak.taccardi I have some stuff to make implementing a foreground service easier and less error-prone, but for non foreground work, WorkManager is a way better solution.
i
FWIW, WorkManager also supports foreground service ran work (and are forward compatible with Android 12): https://developer.android.com/topic/libraries/architecture/workmanager/advanced/long-running
👍 3
o
LifecycleService with lifecycleScope?
2
a
@zak.taccardi Since you're using JobIntentService, I doubt LifecycleService would work. There's though
ServiceLifecycleDispatcher
which is designed to be used when it's impossible to use LifecycleService https://developer.android.com/reference/androidx/lifecycle/ServiceLifecycleDispatcher