foxtrot
Class AsyncTask
java.lang.Object
foxtrot.Task
foxtrot.AsyncTask
public abstract class AsyncTask
- extends Task
A time-consuming task to be executed asynchronously by AsyncWorker.
Users must implement the Task.run() method as they would do with Task.
Exceptions and Errors thrown by the run() method will not
be rethrown automatically by AsyncWorker.post(AsyncTask).
Instead, two callbacks are provided to handle the successful run of the task or
its failure, respectively success(Object) and failure(Throwable),
both called in the Event Dispatch Thread when the task is finished.
AsyncTasks cannot be reused, that is, it is not safe to pass the same instance to
two consecutive calls to AsyncWorker.post(AsyncTask).
Example:
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
}
});
- Version:
- $Revision: 260 $
- See Also:
AsyncWorker
|
Method Summary |
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. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
AsyncTask
public AsyncTask()
finish
protected void finish()
- Called in the Event Dispatch Thread after this AsyncTask is finished.
Normally there is no need to override this method, as it forwards the
result of the task run to success(Object) in case the task
ran successfully, or to failure(Throwable) in case the task
did not complete successfully.
When this method is overridden, a call to Task.getResultOrThrow() must
be done to retrieve the result of the task, or to rethrow the exception
thrown by the task.
- See Also:
success(Object),
failure(Throwable),
Task.getResultOrThrow()
success
public abstract void success(Object result)
- Callback called in the Event Dispatch Thread in case of successful execution
of this AsyncTask.
- Parameters:
result - The result of the task execution, as returned from Task.run()
failure
public abstract void failure(Throwable x)
- Callback called in the Event Dispatch Thread in case of exception thrown
during the execution of this AsyncTask.
- Parameters:
x - The Throwable thrown during the task execution.
Copyright © 2011 KnowledgePlaza. All Rights Reserved.