Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SyncAdapter & SyncResult

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

For instance, when sync is in error due to IOException, we set

syncResult.stats.numIoExceptions++

Then SyncManager must manage the re-send sync until a delay specify by the system.

But how many times the sync is re-call if IOException accurs at each sync? What is the default delay set between each sync? Is that possible to define its own behaviors? Where can I find documentation about that?

like image 380
user932356 Avatar asked Jul 06 '12 12:07

user932356


People also ask

What is sync adapter in Android?

The sync adapter component in your app encapsulates the code for the tasks that transfer data between the device and a server. Based on the scheduling and triggers you provide in your app, the sync adapter framework runs the code in the sync adapter component.

What is Offline Synchronization in Android *?

Offline sync allows end users to interact with a mobile app—viewing, adding, or modifying data—even when there's no network connection. Changes are stored in a local database. Once the device is back online, these changes are synced with the remote backend.

What is main function in Android?

Actually, the main() method is the Android framework class android. app. ActivityThread . This method creates the Main (UI) Thread for an OS process, sets up the Looper on it and starts the event loop.


2 Answers

The SyncResult object has a delayUntil field that you can set from your sync adapter which will delay each following sync by the specified number of seconds. Maybe this is the field you're looking for.

Otherwise, the sync will be rescheduled if

SyncResult.madeSomeProgress() returns true - i.e. some work was successfully accomplished by the sync (corresponding to stats.numDeletes, stats.numInserts > 0, stats.numUpdates > 0)

SyncResult.hasSoftError() returns true - i.e. it failed due to an IOException or because SyncResult.syncAlreadyInProgress was true.

So to answer your question, if IOExceptions occur at EVERY sync, the SyncManager will retry ad infinitum - with exponential backoff.

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

like image 129
43matthew Avatar answered Nov 15 '22 16:11

43matthew


The initial retry 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 retrying the sync by setting SyncResult#tooManyRetries to true.

Source: SyncManager.java

like image 43
Joe Avatar answered Nov 15 '22 15:11

Joe