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?
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.
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.
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.
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 IOException
s 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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With