R - Type of the request specific for the SyncTask implementation.public class SyncTask<R extends SyncTask.Request> extends Object implements Cloneable
BaseSyncManager.
Each instance of SyncTask may be identified by its id that can be obtained via getId().
Creation of instances of SyncTasks is restricted via SyncTask.Builder only.
If synchronization related to a particular SyncTask depends on some additional data that are needed
to perform synchronization logic, these data can be specified via Builder#request(Request).
The synchronization request object should be a simple POJO object that can be processed by Gson
into its String representation and also from it. The request object will be processed into
Json data whenever instance of SyncTask is requested to put its data into extras Bundle
via intoExtras(Bundle) and instantiated from that Json data whenever getRequest(Class)
is called and the request instance has not been parsed yet.
Inheritance instance should override both SyncTask(Builder) and SyncTask(Bundle)
constructors along with intoExtras(Bundle) method to perform custom instantiation logic
via custom implementation of SyncTask.Builder or from/into extras Bundle.
| Modifier and Type | Class and Description |
|---|---|
static class |
SyncTask.Builder<R extends SyncTask.Request>
Builder that can be used to create a new instance of
SyncTask. |
static class |
SyncTask.EmptyRequest
A
SyncTask.Request implementation that may be used for SyncHandlers that
does not require any synchronization request. |
static interface |
SyncTask.Request
Required interface for all synchronization requests.
|
static interface |
SyncTask.State
Defines an annotation for determining set of available states for
SyncTask. |
| Modifier and Type | Field and Description |
|---|---|
static int |
CANCELED
State indicating that
SyncTask has been canceled. |
static int |
DEFAULT_ID
Default id for synchronization task.
|
static SyncTask<SyncTask.EmptyRequest> |
EMPTY
Empty instance of
SyncTask that may be used in order to pass a sync task to a sync
handler that does not require any data from a caller to perform synchronization logic. |
static int |
FAILED
State indicating that
SyncTask has been already executed but an error occurred during
its execution. |
static int |
FINISHED
State indicating that
SyncTask has been already executed without any error. |
static int |
IDLE
Initial state for each new
SyncTask. |
static int |
PENDING
State indicating that
SyncTask is in pending state waiting to be executed. |
static int |
RUNNING
State indicating that
SyncTask is currently being executed. |
| Modifier | Constructor and Description |
|---|---|
protected |
SyncTask(android.os.Bundle extras)
Creates a new instance of SyncTask with data specified within the given extras
Bundle.
|
protected |
SyncTask(SyncTask.Builder<R> builder)
Creates a new instance of SyncTask with data specified within the given builder.
|
protected |
SyncTask(SyncTask other)
Creates a new instance of SyncTask with data of the given one.
|
| Modifier and Type | Method and Description |
|---|---|
protected SyncTask |
clone()
Makes a clone of this task with the same id and request body but with the initial state, which
is
IDLE. |
boolean |
equals(Object other) |
int |
getId()
Returns the id of this task.
|
R |
getRequest(Class<R> classOfRequest)
Returns the request specified for this task.
|
String |
getRequestBody()
Returns a body of the request specified for this task.
|
int |
getState()
Returns the current state of this task.
|
int |
hashCode() |
android.os.Bundle |
intoExtras(android.os.Bundle extras)
Puts all data of this task into the given extras Bundle.
|
String |
toString() |
public static final int IDLE
SyncTask.public static final int PENDING
SyncTask is in pending state waiting to be executed.
Task becomes pending when BaseSyncManager.requestSync(SyncTask) has been called with
that particular task.
public static final int RUNNING
SyncTask is currently being executed.
Task becomes running when BaseSyncAdapter.onPerformSync(Account, Bundle, String, ContentProviderClient, SyncResult)
has been called with extras containing that particular task.
public static final int FINISHED
SyncTask has been already executed without any error.
Task becomes finished when BaseSyncAdapter.onSyncFinished(SyncOperation) has been
called with sync operation containing that particular task.
public static final int FAILED
SyncTask has been already executed but an error occurred during
its execution.
Task becomes finished when BaseSyncAdapter.onSyncFailed(SyncOperation, Exception) has
been called with sync operation containing that particular task.
public static final int CANCELED
SyncTask has been canceled.
Task becomes canceled when BaseSyncManager.cancelSync() has been called.
public static final int DEFAULT_ID
public static final SyncTask<SyncTask.EmptyRequest> EMPTY
SyncTask that may be used in order to pass a sync task to a sync
handler that does not require any data from a caller to perform synchronization logic.protected SyncTask(SyncTask other)
other - The other sync task of which data to copy to the new one.protected SyncTask(SyncTask.Builder<R> builder)
builder - The builder containing data for the new SyncTask instance.protected SyncTask(android.os.Bundle extras)
Note, that proper instantiation of SyncTask from the given extras Bundle
may be performed only if data for the new SyncTask instance has been previously stored within
the given bundle via intoExtras(Bundle) method.
extras - The synchronization extras Bundle containing data for the new SyncTask instance.intoExtras(Bundle)public final int getId()
public final int getState()
@State annotation.public final R getRequest(Class<R> classOfRequest)
null but there is request
body available after this sync task has been created from the extras Bundle the desired
request will be parsed from its body using Gson.classOfRequest - Class used to parse the desired request if it is not parsed yet and there
is request body available.null if there is no request specified.public final String getRequestBody()
null if there is not request specified.public android.os.Bundle intoExtras(android.os.Bundle extras)
SyncTask(Bundle) constructor.extras - The synchronization extras Bundle into which to put data of this task.