How to do initial sync?

I want to sync some documents (Around 10MB) as soon as the user logs in. Also I want to show progress bar as sync progresses. I have added ReplicatorChange listener to Replicator.
The listener method onSyncStatusChange get called and it’s behaviour is inconsistent. I.e after the sync state changes to STOPPED, but onSyncStatusChange gets invoked multiple times even after the sync completion. How can I handle this situation?

Doing an initial sync is the same as doing any other sync. You can’t show progress because the APIs don’t tell you. If you are getting multiple duplicate events triggered you are probably registering an event handler mutiple times and not cleaning it up properly.

Well, you can show a progress bar but it won’t be very accurate. (Accurately computing progress would slow the replicator down a lot.)

The replication is done when its status changes to Stopped. At that point you can start using the database.

However, this isn’t a good user experience. It gives people a bad first impression of an app if they have to sit and wait for it to download stuff before they can use it. If possible, try to make the app useable even before everything has synced.

You can show activity to the user, but not progress, as the “total” value is not useful. I’ve tried to make progress bars and they just don’t work. When the total is updated it’ll just jump back and forth or stick at the end. What I do now is to just show the incrementing “done” value to the user, which is not meaningful but it does show that the app is busy doing something. And it gives a relative feeling if it did a little or a lot.

We currently use manually initiated sync (it was a requirement, ugh), and we also have a lot of data that needs syncing first before the user can start. My goal is to switch to continous (background) replication instead, but there’re still some documents that are really required. We will set the really required Documents to a “initial-sync” channel, so we can do a single-shot pull replication requesting just that channel, and then switch on the continuous general replicators.