All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.stanfy.enroscar.async.internal.TaskAsync Maven / Gradle / Ivy

Go to download

Helper classes and extended abstractions for Android loaders, content resolvers, and DB access.

There is a newer version: 2.1
Show newest version
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);
    }
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy