T
- 异步任务的结果值的类型。public abstract class AsyncResult<T>
extends java.lang.Object
限定符和类型 | 类和说明 |
---|---|
static interface |
AsyncResult.OnCancelListener
异步任务取消事件监听器。
|
构造器和说明 |
---|
AsyncResult() |
限定符和类型 | 方法和说明 |
---|---|
abstract boolean |
isCancelled()
判断异步任务是否已被取消。
|
protected void |
notifyCancelled()
发送异步任务已被取消的通知。
|
abstract void |
onError(java.lang.Throwable throwable)
当异步任务执行失败时,调用该方法发送异常信息。
|
abstract void |
onSuccess(T t)
当异步任务执行成功时,调用该方法发送结果值。
|
void |
setOnCancelListener(AsyncResult.OnCancelListener listener)
设置一个
AsyncResult.OnCancelListener 监听器,用于监听异步任务的取消事件。 |
public abstract void onSuccess(@NonNull T t)
t
- 异步执行得到的结果值,不能为 null。public abstract void onError(@NonNull java.lang.Throwable throwable)
throwable
- 异常信息,不能为 null。public abstract boolean isCancelled()
子类在实现该方法时请确保该方法的线程安全,因为该方法可能会被并发访问。
public void setOnCancelListener(@Nullable AsyncResult.OnCancelListener listener)
AsyncResult.OnCancelListener
监听器,用于监听异步任务的取消事件。listener
- AsyncResult.OnCancelListener
监听器,设置为 null 时将清除上次设置的监听器。protected void notifyCancelled()