Background Sync via WorkManager

Background Sync via WorkManager

Google’s WorkManager library is the typical means that Android developers schedule and manage background tasks in a way that is compatible with a wide range of Android versions.

Here we provide some boilerplate for setting up a WorkManager job to run Judo’s sync opportunistically in the background.

Add WorkManager Dependency

Add the following the dependencies block in your build.gradle:


implementation ''

Kotlin KTS:


Define Worker

Create a PeriodicWorkRequest that runs the Judo SDK’s sync:

import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit
import app.judo.sdk.api.Judo

class JudoSyncWorker(appContext: Context, workerParameters: WorkerParameters): Worker(appContext, workerParameters) {
    companion object {
        private const val TAG = "JudoSyncWorker"

    override fun doWork(): Result {
        val latch = CountDownLatch(1)

        Judo.performSync {

        try {
        } catch (error: Exception) {
            Log.e(TAG, "Unable to complete background Judo sync")
            return Result.failure()
        return Result.success()

## Register Task

Finally, in your Application class’ onCreate, create and register a work request:

 val judoWorkRequest = PeriodicWorkRequest.Builder(, 1, TimeUnit.HOURS)
            // some recommended constraints in order to be considerate about the user's battery and network.

WorkManager.getInstance(this).enqueueUniquePeriodicWork("judo-sync", ExistingPeriodicWorkPolicy.REPLACE, judoWorkRequest)

You’ve completed the initial integration! However, other optional steps remain for for more advanced features, namely User Identification and Personalization, handling both Integrating with Analytics.

Ask Our Community

If you have questions about the Judo editor, or developer questions about SDK integration, join the community and start a conversation!

Go to Judo Support Forum