Runs a new coroutine and **blocks** the current thread _interruptibly_ until its completion.
Do you really need to block the current thread for your operation ?
Can’t you use a coroutine scope (scoped to service lifecycle) to run your job ?
satyan
02/13/2020, 1:50 PM
+ SyncAdapter seems to be deprecated.
You should use a WorkManager instead (A CoroutineWorkManager even 😏 )
d
dave08
02/13/2020, 1:51 PM
How does the sync adapter know that I finished? I really do need the sync adapter's UI that links the process to a custom Android Account...
dave08
02/13/2020, 1:51 PM
But I do the actual process in a
WorkManager
Worker
...
dave08
02/13/2020, 1:55 PM
I just need the sync adapter not to schedule a new work until the previous one is finished:
Copy code
override fun onPerformSync(
account: Account,
bundle: Bundle,
s: String,
contentProviderClient: ContentProviderClient,
syncResult: SyncResult
) = runBlocking {
i { "Running sync..." }
val workManager = WorkManager.getInstance(context)
val syncRequest = OneTimeWorkRequestBuilder<SyncWork>()
.build()
workManager.enqueueUniqueWork(
SYNC_WORK_UNIQUE_NAME, ExistingWorkPolicy.APPEND, syncRequest
).await()
syncResult += workManager.getWorkInfosByTagLiveData(SYNC_WORK_UNIQUE_NAME)
.asFlow().onEach {
d { "WorkInfo (${syncRequest.id}): $it" }
}.singleOrNull()?.firstOrNull { it.state.isFinished }?.outputData
Unit
}
dave08
02/13/2020, 1:55 PM
But if it gets interrupted... it seems to crash.
l
louiscad
02/16/2020, 10:32 AM
It seems? Or it does?
d
dave08
02/17/2020, 3:11 AM
Crashylitics is a bit funny, in this case, I have seen crashes myself, but there are certain crash reports, that I really don't see how it could have crashed there since I used catch all over in those places @louiscad. That's why I said that it seems to crash = according to crashylitics.