-
-
Save aftabsikander/8cc89d1a45d217153b08 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 hidden or 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