io.adtrace.sdk.scheduler.AsyncTaskExecutor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of android-sdk Show documentation
Show all versions of android-sdk Show documentation
The AdTrace SDK for Android
package io.adtrace.sdk.scheduler;
import android.os.Handler;
import android.os.Looper;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public abstract class AsyncTaskExecutor {
protected abstract Result doInBackground(Params[] params);
protected void onPreExecute() { }
protected void onPostExecute(Result result) { }
@SafeVarargs
public final AsyncTaskExecutor execute(final Params ... params) {
onPreExecute();
final Handler handler = new Handler(Looper.getMainLooper());
ExecutorService executorService = Executors.newSingleThreadExecutor();
executorService.execute(new Runnable() {
@Override
public void run() {
final Result result = doInBackground(params);
handler.post(new Runnable() {
@Override
public void run() {
onPostExecute(result);
}
});
}
});
return this;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy