SyncAdapter & SyncResult

I want to know what the default behavior of SyncManager is when we use the SyncResult object during the onPerformSync() operation

For example, when the synchronization is erroneous due to an IOException , we set

 syncResult.stats.numIoExceptions++ 

Then, SyncManager must control the resubmission synchronization until the system reports a delay.

But how many times does the chime synchronization if an IOException matches each synchronization? What is the default delay between each synchronization? Can I define my own behavior? Where can I find documentation about this?

+7
source share
2 answers

The SyncResult object has a delayUntil field, which you can set from the synchronization adapter, which will delay each subsequent synchronization for the specified number of seconds. Perhaps this is the field you are looking for.

Otherwise, the synchronization will be postponed if

SyncResult.madeSomeProgress() returns true - that is, some work was successfully performed by synchronization (corresponding to stats.numDeletes , stats.numInserts > 0 , stats.numUpdates > 0 )

SyncResult.hasSoftError() returns true, i.e. Failure due to an IOException or because the value of SyncResult.syncAlreadyInProgress true.

So, to answer your question, if an IOException occurs at every synchronization, SyncManager will repeat infinity - with exponential deviation.

The caveat is that the synchronization adapter can set SyncResult.tooManyRetries = true , which will indicate to SyncManager that the synchronization will not be rescheduled.

+6
source

Start Repeat Time:

 /** * When retrying a sync for the first time use this delay. After that * the retry time will double until it reached MAX_SYNC_RETRY_TIME. * In milliseconds. */ private static final long INITIAL_SYNC_RETRY_TIME_IN_MS = 30 * 1000; // 30 seconds 

You can tell the framework to stop re-synchronizing by setting SyncResult#tooManyRetries to true .

Source: SyncManager.java

+1
source

All Articles