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

org.robolectric.shadows.ShadowAsyncTaskBridge Maven / Gradle / Ivy

package org.robolectric.shadows;

import android.os.AsyncTask;
import org.robolectric.annotation.internal.DoNotInstrument;
import org.robolectric.util.ReflectionHelpers;
import org.robolectric.util.ReflectionHelpers.ClassParameter;

/**
 * Bridge between shadows and {@link android.os.AsyncTask}.
 */
@DoNotInstrument
public class ShadowAsyncTaskBridge {
  private AsyncTask asyncTask;

  public ShadowAsyncTaskBridge(AsyncTask asyncTask) {
    this.asyncTask = asyncTask;
  }

  public Result doInBackground(Params... params) {
    return ReflectionHelpers.callInstanceMethod(asyncTask, "doInBackground", ClassParameter.from(Object[].class, params));
  }

  public void onPreExecute() {
    ReflectionHelpers.callInstanceMethod(asyncTask, "onPreExecute");
  }

  public void onPostExecute(Result result) {
    ReflectionHelpers.callInstanceMethod(asyncTask, "onPostExecute", ClassParameter.from(Object.class, result));
  }

  public void onProgressUpdate(Progress... values) {
    ReflectionHelpers.callInstanceMethod(asyncTask, "onProgressUpdate", ClassParameter.from(Object[].class, values));
  }

  public void onCancelled() {
    ReflectionHelpers.callInstanceMethod(asyncTask, "onCancelled");
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy