com.stanfy.enroscar.async.internal.TaskAsync Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of enroscar-content Show documentation
Show all versions of enroscar-content Show documentation
Helper classes and extended abstractions for Android loaders, content resolvers, and DB access.
package com.stanfy.enroscar.async.internal;
import com.stanfy.enroscar.async.Async;
import java.util.concurrent.Callable;
/**
* Implementation of {@link Async} based on AsyncTask.
* @author Roman Mazur - Stanfy (http://stanfy.com)
*/
public class TaskAsync> extends BaseAsync {
/** Task instance. */
final T task;
/** Android AsyncTask. */
private AsyncTaskWithDelegate asyncTask;
public TaskAsync(final T task) {
this.task = task;
}
@Override
protected void onTrigger() {
doCancel();
asyncTask = new AsyncTaskWithDelegate<>(task, this);
asyncTask.execute();
}
@Override
protected void onCancel() {
doCancel();
}
private void doCancel() {
if (asyncTask != null) {
asyncTask.cancel(true);
}
}
}