public abstract class BaseSyncManager extends Object implements OnSyncTaskStateChangeListener
Account that should be picked by a specific BaseSyncManager implementation
whenever pickAccountForSync() is called.
To request synchronization for a specific SyncTask call requestSync(SyncTask)
method. If a global synchronization should be performed, call requestGlobalSync().
Base synchronization manager class implements also some configuration methods like to start/stop
automatic synchronization via startAutomaticSync() and stopAutomaticSync() or
to check whether there are some synchronization operations pending or active via isSyncPedning()
and isSyncPedning(). Any additional methods may be freely implemented by the inheritance
hierarchies.
| Modifier and Type | Field and Description |
|---|---|
protected String |
mAuthority
Deprecated.
Use
getAuthority() instead. |
protected android.content.Context |
mContext
Deprecated.
Use
getContext() instead. |
| Constructor and Description |
|---|
BaseSyncManager(android.content.Context context,
String authority)
Creates a new instance of BaseSyncManager with the given context and authority.
|
| Modifier and Type | Method and Description |
|---|---|
void |
cancelSync()
Cancels any active or pending synchronizations that match the content authority specified for
this manager and account picked for synchronization by this manager implementation.
|
String |
getAuthority()
Returns the content authority with which has been this manager created.
|
android.content.Context |
getContext()
Returns the context with which has been this manager created.
|
boolean |
isSyncActive()
Checks whether there is currently a synchronization being processed for the content authority
specified for this manager and account picked for synchronization by this manager implementation.
|
boolean |
isSyncPedning()
Checks whether there are any pending synchronizations for the content authority specified for
this manager and account picked for synchronization by this manager implementation.
|
protected void |
onCancelSync(android.accounts.Account account)
Invoked whenever
cancelSync() is called. |
void |
onSyncTaskStateChanged(SyncTask syncTask,
android.accounts.Account account)
Invoked whenever a state of the specified syncTask has been changed.
|
protected abstract android.accounts.Account |
pickAccountForSync()
Called to pick account for the current synchronization related request dispatched to this
manager.
|
void |
requestGlobalSync()
Same as
requestSync(SyncTask) with sync task with SyncTask.DEFAULT_ID id. |
void |
requestSync(SyncTask syncTask)
Requests synchronization operation to be performed for the specified syncTask.
|
protected boolean |
shouldRequestSync(SyncTask syncTask,
android.accounts.Account account)
Called from
requestSync(SyncTask) to check whether a synchronization should be requested
for the specified syncTask and account. |
void |
startAutomaticSync()
Starts automatic synchronization for the content authority specified for this manager and
account picked for synchronization by this manager implementation.
|
void |
stopAutomaticSync()
Stops automatic synchronization for the content authority specified for this manager and
account picked for synchronization by this manager implementation.
|
@Deprecated protected final android.content.Context mContext
getContext() instead.@Deprecated protected final String mAuthority
getAuthority() instead.ContentResolver.public BaseSyncManager(android.content.Context context,
String authority)
context - Context that may be used by inheritance hierarchies to access application
data and services needed to perform requested synchronization.authority - The content authority which should the manager use when requesting synchronization
operations via ContentResolver.getContext(),
getAuthority()public final android.content.Context getContext()
BaseSyncManager(Context, String)public final String getAuthority()
ContentResolver.BaseSyncManager(Context, String)public void startAutomaticSync()
stopAutomaticSync(),
ContentResolver.setSyncAutomatically(Account, String, boolean)public void stopAutomaticSync()
startAutomaticSync(),
ContentResolver.setSyncAutomatically(Account, String, boolean)public void requestGlobalSync()
requestSync(SyncTask) with sync task with SyncTask.DEFAULT_ID id.public void requestSync(SyncTask syncTask)
If there is successfully picked synchronization account, a Bundle for sync adapter
is created with the following extras:
SYNC_EXTRAS_MANUAL: trueSYNC_EXTRAS_EXPEDITED: trueSyncTask put into the extras BundlesyncTask - The desired task for which to request synchronization. This task will be put
into Bundle along with other sync extras for the sync adapter registered
for this Android application.requestGlobalSync(),
ContentResolver.requestSync(Account, String, Bundle)protected boolean shouldRequestSync(SyncTask syncTask, android.accounts.Account account)
requestSync(SyncTask) to check whether a synchronization should be requested
for the specified syncTask and account.
This implementation returns always true.
syncTask - The sync task for which to check if synchronization should be requested.account - The account for which to request synchronization.True if requestSync(SyncTask) should proceed and request synchronization
via ContentResolver.requestSync(Account, String, Bundle) for the task and account,
false otherwise.pickAccountForSync()public void onSyncTaskStateChanged(SyncTask syncTask, android.accounts.Account account)
OnSyncTaskStateChangeListeneronSyncTaskStateChanged in interface OnSyncTaskStateChangeListenersyncTask - The task of which state has changed.account - The account for which has been requested synchronization associated with the
sync task.SyncTask.getState()public boolean isSyncActive()
True if synchronization is active at this time, false otherwise.ContentResolver.isSyncActive(Account, String),
isSyncPedning(),
cancelSync()public boolean isSyncPedning()
True if there are some synchronizations pending, false otherwise.ContentResolver.isSyncPending(Account, String),
isSyncActive(),
cancelSync()public void cancelSync()
ContentResolver.cancelSync(Account, String),
isSyncActive(),
isSyncPedning()protected void onCancelSync(android.accounts.Account account)
cancelSync() is called.
Default implementation cancels current sync via ContentResolver.cancelSync(Account, String)
for the specified account and authority specified for this manager.
account - The account picked via pickAccountForSync().protected abstract android.accounts.Account pickAccountForSync()
startAutomaticSync(),
stopAutomaticSync(), requestGlobalSync(), requestSync(SyncTask),
isSyncActive(), isSyncPedning(), cancelSync().