initialize
Initializes the sync process that keeps the app's data synchronized with Firestore.
This method enqueues a unique WorkManager work request that:
Runs immediately on app startup (if network is available)
Ensures only one sync worker runs at any time
Retries up to 3 times on failure with exponential backoff
When to Call
Call this method once from your Application's onCreate() method:
class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
Hilt.createAndroidLogger(this)
Sync.initialize(this) // Initialize sync
}
}Behavior
First Call: Enqueues the sync worker
Subsequent Calls: Ignored due to
ExistingWorkPolicy.KEEPNetwork Required: Sync only runs when network is connected
Expedited: Runs as expedited work when possible for faster initial sync
Thread Safety
This method is thread-safe and can be called from any thread. WorkManager handles internal synchronization.
Error Handling
WorkManager automatically retries failed sync operations
Errors are logged via Timber
Failed syncs don't crash the app; they'll be retried later
Parameters
The application context. Use applicationContext to avoid memory leaks.