public abstract class AbstractBackgroundTask extends AsyncTask implements BackgroundTask
AbstractBackgroundTask takes care of the common
code for a BackgroundTask based on the
AsyncTask API. The cancellation contained here is for
a polling-based cancel mechanism. AsyncTask.CancelledExceptionCANCELLED_RESULT, STATUS_CANCELLED, STATUS_COMPLETED, STATUS_FAILED, STATUS_READY, STATUS_RUNNING| Constructor and Description |
|---|
AbstractBackgroundTask() |
| Modifier and Type | Method and Description |
|---|---|
void |
cancel()
Attempts to cancel the current task in progress.
|
protected void |
cancelTaskImpl()
Implementation-specific work to cancel this running task should go
here.
|
int |
getProgress()
Fetches the current progress of the query task.
|
java.lang.String |
getProgressText()
Fetches a human-readable (translated) descriptive text that
describes what the task is currently doing.
|
protected abstract AsyncScheduler |
getSchedulerImpl()
Requests the scheduler that this task was scheduled with.
|
protected boolean |
isCancelledImpl()
Return whether the task is marked for cancellation, to be implemented
by the implementation.
|
protected void |
requestCancelImpl()
Request to cancel the task in-progress.
|
protected java.lang.Object |
runImpl()
Wrapper for the task implementation to catch and report
task failures in the form of
RuntimeExceptions. |
protected abstract java.lang.Object |
runTaskImpl()
Implementation of this task.
|
void |
setProgress(int value)
Sets the current progress value.
|
protected void |
setProgressFromSubTask(BackgroundTask task,
int rangeStart,
int rangeEnd)
Utility routine to update the task progress based on a subtask's
progress.
|
protected void |
setProgressFromSubTask(int subValue,
int rangeStart,
int rangeEnd)
Utility routine to update our task's progress based on a subtask.
|
void |
setProgressText(java.lang.String text)
Sets the human-readable descriptive text describing what the
task is currently doing.
|
bailIfCancelled, getResult, getStatus, isFinished, requestCancel, run, sleep, waitUntilFinished, waitUntilFinishedclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitisFinished, waitUntilFinishedpublic final void cancel()
cancel in interface BackgroundTaskprotected abstract AsyncScheduler getSchedulerImpl()
protected abstract java.lang.Object runTaskImpl()
throws AsyncTask.CancelledException
CancelledException - if the task has been cancelledAsyncTask.CancelledExceptionprotected void cancelTaskImpl()
protected final java.lang.Object runImpl()
throws AsyncTask.CancelledException
RuntimeExceptions.runImpl in class AsyncTaskCancelledException - if the task has been cancelledAsyncTask.CancelledExceptionprotected final void requestCancelImpl()
requestCancelImpl in class AsyncTaskprotected final boolean isCancelledImpl()
isCancelledImpl in class AsyncTaskprotected void setProgressFromSubTask(int subValue,
int rangeStart,
int rangeEnd)
subValue - the sub-task's progress (0-100)rangeStart - the range start of the main task's progressrangeEnd - the range end of the main task's progressprotected void setProgressFromSubTask(BackgroundTask task, int rangeStart, int rangeEnd)
task - the sub-taskrangeStart - the range start of the main task's progressrangeEnd - the range end of the main task's progresspublic final int getProgress()
getProgress in interface BackgroundTaskpublic final void setProgress(int value)
value - the current value, as a value between 0 and 100public final java.lang.String getProgressText()
getProgressText in interface BackgroundTaskpublic final void setProgressText(java.lang.String text)
text - the descriptive progress text