Created
March 8, 2023 10:17
-
-
Save tunjid/0f29c343d5cf503579888a1cfc54883f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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