Last active
October 3, 2015 20:06
-
-
Save technoir42/7510ab0d89a25847d579 to your computer and use it in GitHub Desktop.
Generic implementation of AsyncTaskLoader. See http://developer.android.com/reference/android/content/AsyncTaskLoader.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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