https://kotlinlang.org logo
#coroutines
Title
# coroutines
z

zak.taccardi

02/18/2021, 7:57 PM
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

louiscad

02/18/2021, 8:07 PM
@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

Ian Lake

02/18/2021, 8:40 PM
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

Orhan Tozan

02/18/2021, 9:18 PM
LifecycleService with lifecycleScope?
2
a

Ahmed Ibrahim

02/19/2021, 11:21 AM
@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
2 Views