public abstract class PriorityAsyncTask<Params,Progress,Result> extends Object
限定符和类型 | 字段和说明 |
---|---|
static Executor |
sDefaultExecutor |
构造器和说明 |
---|
PriorityAsyncTask()
Creates a new asynchronous task.
|
限定符和类型 | 方法和说明 |
---|---|
boolean |
cancel(boolean mayInterruptIfRunning) |
protected abstract Result |
doInBackground(Params... params)
Override this method to perform a computation on a background thread.
|
PriorityAsyncTask<Params,Progress,Result> |
execute(Params... params) |
static void |
execute(Runnable runnable)
Convenience version of
execute(Object...) for use with
a simple Runnable object. |
static void |
execute(Runnable runnable,
Priority priority)
Convenience version of
execute(Object...) for use with
a simple Runnable object. |
PriorityAsyncTask<Params,Progress,Result> |
executeOnExecutor(Executor exec,
Params... params) |
Result |
get()
Waits if necessary for the computation to complete, and then
retrieves its result.
|
Result |
get(long timeout,
TimeUnit unit)
Waits if necessary for at most the given time for the computation
to complete, and then retrieves its result.
|
Priority |
getPriority() |
Runnable |
getRunnable() |
boolean |
isCancelled()
Returns true if this task was cancelled before it completed
normally.
|
protected void |
onCancelled()
Applications should preferably override
onCancelled(Object) . |
protected void |
onCancelled(Result result)
Runs on the UI thread after
cancel(boolean) is invoked and
doInBackground(Object[]) has finished. |
protected void |
onPostExecute(Result result)
Runs on the UI thread after
doInBackground(Params...) . |
protected void |
onPreExecute()
Runs on the UI thread before
doInBackground(Params...) . |
protected void |
onProgressUpdate(Progress... values)
Runs on the UI thread after
publishProgress(Progress...) is invoked. |
protected void |
publishProgress(Progress... values)
This method can be invoked from
doInBackground(Params...) to
publish updates on the UI thread while the background computation is
still running. |
void |
setPriority(Priority priority) |
public static final Executor sDefaultExecutor
public PriorityAsyncTask()
public Priority getPriority()
public void setPriority(Priority priority)
public Runnable getRunnable()
protected abstract Result doInBackground(Params... params)
execute(Params...)
by the caller of this task.
This method can call publishProgress(Progress...)
to publish updates
on the UI thread.params
- The parameters of the task.onPreExecute()
,
onPostExecute(Result)
,
publishProgress(Progress...)
protected void onPreExecute()
doInBackground(Params...)
.protected void onPostExecute(Result result)
Runs on the UI thread after doInBackground(Params...)
. The
specified result is the value returned by doInBackground(Params...)
.
This method won't be invoked if the task was cancelled.
result
- The result of the operation computed by doInBackground(Params...)
.onPreExecute()
,
doInBackground(Params...)
,
onCancelled(Object)
protected void onProgressUpdate(Progress... values)
publishProgress(Progress...)
is invoked.
The specified values are the values passed to publishProgress(Progress...)
.values
- The values indicating progress.publishProgress(Progress...)
,
doInBackground(Params...)
protected void onCancelled(Result result)
Runs on the UI thread after cancel(boolean)
is invoked and
doInBackground(Object[])
has finished.
The default implementation simply invokes onCancelled()
and
ignores the result. If you write your own implementation, do not call
super.onCancelled(result)
.
result
- The result, if any, computed in
doInBackground(Object[])
, can be nullcancel(boolean)
,
isCancelled()
protected void onCancelled()
Applications should preferably override onCancelled(Object)
.
This method is invoked by the default implementation of
onCancelled(Object)
.
Runs on the UI thread after cancel(boolean)
is invoked and
doInBackground(Object[])
has finished.
public final boolean isCancelled()
cancel(boolean)
on the task,
the value returned by this method should be checked periodically from
doInBackground(Object[])
to end the task as soon as possible.cancel(boolean)
public final boolean cancel(boolean mayInterruptIfRunning)
mayInterruptIfRunning
- true if the thread executing this
task should be interrupted; otherwise, in-progress tasks are allowed
to complete.isCancelled()
,
onCancelled(Object)
public final Result get() throws InterruptedException, ExecutionException
CancellationException
- If the computation was cancelled.ExecutionException
- If the computation threw an exception.InterruptedException
- If the current thread was interrupted
while waiting.public final Result get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
timeout
- Time to wait before cancelling the operation.unit
- The time unit for the timeout.CancellationException
- If the computation was cancelled.ExecutionException
- If the computation threw an exception.InterruptedException
- If the current thread was interrupted
while waiting.TimeoutException
- If the wait timed out.public final PriorityAsyncTask<Params,Progress,Result> execute(Params... params)
params
- The parameters of the task.IllegalStateException
- If execute has invoked.executeOnExecutor(Executor, Object[])
,
execute(Runnable)
public final PriorityAsyncTask<Params,Progress,Result> executeOnExecutor(Executor exec, Params... params)
exec
- The executor to use.params
- The parameters of the task.IllegalStateException
- If execute has invoked.execute(Object[])
public static void execute(Runnable runnable)
execute(Object...)
for use with
a simple Runnable object. See execute(Object[])
for more
information on the order of execution.public static void execute(Runnable runnable, Priority priority)
execute(Object...)
for use with
a simple Runnable object. See execute(Object[])
for more
information on the order of execution.protected final void publishProgress(Progress... values)
doInBackground(Params...)
to
publish updates on the UI thread while the background computation is
still running. Each call to this method will trigger the execution of
onProgressUpdate(Progress...)
on the UI thread.
onProgressUpdate(Progress...)
will note be called if the task has been
canceled.values
- The progress values to update the UI with.onProgressUpdate(Progress...)
,
doInBackground(Params...)