public abstract class AsyncTask extends Task
AsyncWorker. Task.run() method as they would do with Task. AsyncWorker.post(AsyncTask). success(Object) and failure(Throwable),
both called in the Event Dispatch Thread when the task is finished. AsyncWorker.post(AsyncTask).
AsyncTask task = new AsyncTask()
{
public Object run() throws Exception
{
// Called in a worker thread
Thread.sleep(1000);
return new ArrayList();
}
public void success(Object result)
{
// Called in the Event Dispatch Thread
List result = (List)result;
// Do something with the List
}
public void failure(Throwable x)
{
// Report exception to the user, or just log it
}
});
AsyncWorker| Constructor and Description |
|---|
AsyncTask() |
| Modifier and Type | Method and Description |
|---|---|
abstract void |
failure(Throwable x)
Callback called in the Event Dispatch Thread in case of exception thrown
during the execution of this AsyncTask.
|
protected void |
finish()
Called in the Event Dispatch Thread after this AsyncTask is finished.
|
abstract void |
success(Object result)
Callback called in the Event Dispatch Thread in case of successful execution
of this AsyncTask.
|
getResultOrThrow, isCompleted, runprotected void finish()
success(Object) in case the task
ran successfully, or to failure(Throwable) in case the task
did not complete successfully. Task.getResultOrThrow() must
be done to retrieve the result of the task, or to rethrow the exception
thrown by the task.public abstract void success(Object result)
result - The result of the task execution, as returned from Task.run()public abstract void failure(Throwable x)
x - The Throwable thrown during the task execution.Copyright © 2002-2011. All Rights Reserved.