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

android.os.AsyncTask Maven / Gradle / Ivy

There is a newer version: 1.4.1
Show newest version
package android.os;


import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public abstract class AsyncTask {
  public void execute(final Params... args) {
    final ExecutorService executor = Executors.newSingleThreadExecutor();
    executor.execute(new Runnable() {
      @Override public void run() {
        onPreExecute();
        executor.execute(new Runnable(){
          @Override public void run() {
            final Result result = doInBackground(args);
            executor.execute(new Runnable() {
              @Override public void run() {
                onPostExecute(result);
                executor.shutdown();
              }
            });
          }
        });
      }
    });
  }

  protected void onPreExecute(){}
  protected abstract Result doInBackground(Params... params);
  protected void onPostExecute(Result result){}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy