Skip to content

Instantly share code, notes, and snippets.

@technoir42
Last active October 3, 2015 20:06
Show Gist options
  • Save technoir42/7510ab0d89a25847d579 to your computer and use it in GitHub Desktop.
Save technoir42/7510ab0d89a25847d579 to your computer and use it in GitHub Desktop.
import android.content.Context;
import android.support.v4.content.AsyncTaskLoader;
public abstract class AsyncLoader<T> extends AsyncTaskLoader<T> {
private T mResult;
public AsyncLoader(Context context) {
super(context);
}
@Override
public void deliverResult(T result) {
if (isReset()) {
return;
}
mResult = result;
if (isStarted()) {
super.deliverResult(result);
}
}
@Override
protected void onStartLoading() {
if (mResult != null) {
deliverResult(mResult);
}
if (takeContentChanged() || mResult == null) {
forceLoad();
}
}
@Override
protected void onStopLoading() {
cancelLoad();
}
@Override
protected void onReset() {
super.onReset();
onStopLoading();
mResult = null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment