com.stanfy.enroscar.async.internal.AsyncTaskWithDelegate 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 android.os.AsyncTask;
import java.util.concurrent.Callable;
final class AsyncTaskWithDelegate extends AsyncTask {
/** Delegate. */
BaseAsync async;
/** Task. */
private Callable task;
/** Caught error. */
private Exception error;
protected AsyncTaskWithDelegate(final Callable task) {
this(task, null);
}
protected AsyncTaskWithDelegate(final Callable task, final BaseAsync async) {
this.async = async;
this.task = task;
}
@Override
protected final D doInBackground(Void... params) {
try {
return task.call();
} catch (Exception e) {
error = e;
return null;
}
}
@Override
protected final void onPostExecute(final D d) {
if (error != null) {
async.postError(error);
} else {
async.postResult(d);
}
}
}