Skip to content

Instantly share code, notes, and snippets.

@tunjid
Created March 8, 2023 10:17
Show Gist options
  • Save tunjid/0f29c343d5cf503579888a1cfc54883f to your computer and use it in GitHub Desktop.
Save tunjid/0f29c343d5cf503579888a1cfc54883f to your computer and use it in GitHub Desktop.
// Copyright 2023 Google LLC.
// SPDX-License-Identifier: Apache-2.0
class SyncInitializer : Initializer<Sync> {
override fun create(context: Context): Sync {
WorkManager.getInstance(context).apply {
// Run sync on app startup and ensure only one sync worker runs at any time
enqueueUniqueWork(
SyncWorkName,
ExistingWorkPolicy.KEEP,
SyncWorker.startUpSyncWork(),
)
}
return Sync
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment