java.lang.Object | |
↳ | android.content.SyncRequest.Builder |
Builder class for a
SyncRequest
. As you build your SyncRequest this class will also
perform validation.
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
|
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
|
Performs validation over the request and throws the runtime exception
IllegalArgumentException
if this validation fails.
|
||||||||||
|
|
||||||||||
|
An expedited sync runs immediately and will preempt another non-expedited running sync.
|
||||||||||
|
Optional developer-provided extras handed back in
onPerformSync(Account, Bundle, String, ContentProviderClient, SyncResult)
occurs.
|
||||||||||
|
Convenience function for setting
SYNC_EXTRAS_IGNORE_BACKOFF
.
|
||||||||||
|
Convenience function for setting
SYNC_EXTRAS_IGNORE_SETTINGS
.
|
||||||||||
|
Convenience function for setting
SYNC_EXTRAS_MANUAL
.
|
||||||||||
|
Convenience function for setting
SYNC_EXTRAS_DO_NOT_RETRY
.
|
||||||||||
|
Specify an authority and account for this transfer.
|
||||||||||
|
Request that a sync occur immediately.
|
||||||||||
|
Build a periodic sync.
|
[Expand]
Inherited Methods
|
|||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
Performs validation over the request and throws the runtime exception
IllegalArgumentException
if this validation fails.
disallow | true to enforce that this transfer not occur on metered networks. Default false. |
---|
An expedited sync runs immediately and will preempt another non-expedited running sync.
Not valid for periodic sync and will throw an
IllegalArgumentException
in
build()
.
expedited | whether to run expedited. Default false. |
---|
Optional developer-provided extras handed back in
onPerformSync(Account, Bundle, String, ContentProviderClient, SyncResult)
occurs. This bundle is copied into the SyncRequest
returned by
build()
.
Example:
String[] syncItems = {"dog", "cat", "frog", "child"}; SyncRequest.Builder builder = new SyncRequest.Builder() .setSyncAdapter(dummyAccount, dummyProvider) .syncOnce(5 * MINUTES_IN_SECS); for (String syncData : syncItems) { Bundle extras = new Bundle(); extras.setString("data", syncData); builder.setExtras(extras); ContentResolver.sync(builder.build()); // Each sync() request is for a unique sync. }Only values of the following types may be used in the extras bundle:
bundle | extras bundle to set. |
---|
Convenience function for setting
SYNC_EXTRAS_IGNORE_BACKOFF
.
Force the sync scheduling process to ignore any back-off that was the result of a failed
sync, as well as to invalidate any
delayUntil
value that may have
been set by the adapter. Successive failures will not honor this flag. Not valid for
periodic sync and will throw an
IllegalArgumentException
in
build()
.
ignoreBackoff | ignore back-off settings. Default false. |
---|
Convenience function for setting
SYNC_EXTRAS_IGNORE_SETTINGS
.
A sync can specify that system sync settings be ignored (user has turned sync off). Not
valid for periodic sync and will throw an
IllegalArgumentException
in
build()
.
ignoreSettings | true to ignore the sync automatically settings. Default false. |
---|
Convenience function for setting
SYNC_EXTRAS_MANUAL
.
A manual sync is functionally equivalent to calling
setIgnoreBackoff(boolean)
and
setIgnoreSettings(boolean)
. Not valid for periodic sync and will throw an
IllegalArgumentException
in
build()
.
isManual | User-initiated sync or not. Default false. |
---|
Convenience function for setting
SYNC_EXTRAS_DO_NOT_RETRY
.
A one-off sync operation that fails will be retried with exponential back-off unless
this is set to false. Not valid for periodic sync and will throw an
IllegalArgumentException
in build().
noRetry | true to not retry a failed sync. Default false. |
---|
Specify an authority and account for this transfer.
account | Account to sync. Can be null unless this is a periodic sync. |
---|---|
authority | String identifying which content provider to sync. |
Request that a sync occur immediately. Example
SyncRequest.Builder builder = (new SyncRequest.Builder()).syncOnce();
Build a periodic sync. Either this or syncOnce()
must
be called for this builder.
Syncs are identified by target
android.provider
/
Account
and by the contents of the extras bundle.
You cannot reuse the same builder for one-time syncs (by calling this function) after
having specified a periodic sync. If you do, an
IllegalArgumentException
will be thrown.
Example usage.
Request a periodic sync every 5 hours with 20 minutes of flex. SyncRequest.Builder builder = (new SyncRequest.Builder()).syncPeriodic(5 * HOUR_IN_SECS, 20 * MIN_IN_SECS); Schedule a periodic sync every hour at any point in time during that hour. SyncRequest.Builder builder = (new SyncRequest.Builder()).syncPeriodic(1 * HOUR_IN_SECS, 1 * HOUR_IN_SECS);N.B.: Periodic syncs are not allowed to have any of
SYNC_EXTRAS_DO_NOT_RETRY
,
SYNC_EXTRAS_IGNORE_BACKOFF
,
SYNC_EXTRAS_IGNORE_SETTINGS
,
SYNC_EXTRAS_INITIALIZE
,
SYNC_EXTRAS_FORCE
,
SYNC_EXTRAS_EXPEDITED
,
SYNC_EXTRAS_MANUAL
set to true. If any are supplied then an
IllegalArgumentException
will
be thrown.
pollFrequency | the amount of time in seconds that you wish to elapse between periodic syncs. |
---|---|
beforeSeconds |
the amount of flex time in seconds before
pollFrequency
that you permit for the sync to take
place. Must be less than
pollFrequency
.
|