It seems like `runBlocking {}` isn't possible anym...
# android
d
It seems like
runBlocking {}
isn't possible anymore, since you can't use the
lifecycleScope
with it...
l
Using
runBlocking
on Android for something other than tests is almost always a bad idea.
d
I have a SyncAdapter with this:
Copy code
override fun onPerformSync(
			account: Account,
			bundle: Bundle,
			s: String,
			contentProviderClient: ContentProviderClient,
			syncResult: SyncResult
	) = coroutineScope.launch {

		syncEventTrigger.onSyncStart(context, syncResult)
				.onStart { i { "Sync Started" } }
				.onCompletion { i { "Sync Stopped" } }
				.collect()
    }.let { Unit }
But I don't want the onPerformSync to exit until the
collect
finishes...
I'm assuming that since the `Service`'s
lifecycleScope
is using
Dispatchers.Main.immediate
, that it will block the service until the sync is finished. Am I right?
But then, maybe that's a bit flaky to count on such things... so
runBlocking
might be better here...
l
You're not right, the service will not be "blocked". It'll stay there until you ask it to stop or the user or Android stops it.
d
That's for a regular service, but a SyncAdapter binds to a service, so doesn't the service get stopped when Android unbinds it at the end of the Sync?
l
You can check the sources of
LifecycleService
from your IDE to find out, and be sure.