use of android.content.AsyncTaskLoader in project muzei by romannurik.
the class FullScreenActivity method onCreateLoader.
@Override
public Loader<Bitmap> onCreateLoader(int id, Bundle args) {
return new AsyncTaskLoader<Bitmap>(this) {
private ContentObserver mContentObserver;
private Bitmap mImage;
@Override
protected void onStartLoading() {
if (mImage != null) {
deliverResult(mImage);
}
if (mContentObserver == null) {
mContentObserver = new ContentObserver(null) {
@Override
public void onChange(boolean selfChange) {
onContentChanged();
}
};
getContentResolver().registerContentObserver(MuzeiContract.Artwork.CONTENT_URI, true, mContentObserver);
}
forceLoad();
}
@Override
public Bitmap loadInBackground() {
try {
mArtwork = MuzeiContract.Artwork.getCurrentArtwork(FullScreenActivity.this);
mImage = MuzeiContract.Artwork.getCurrentArtworkBitmap(FullScreenActivity.this);
return mImage;
} catch (FileNotFoundException e) {
Log.e(TAG, "Error getting artwork", e);
return null;
}
}
@Override
protected void onReset() {
super.onReset();
mImage = null;
if (mContentObserver != null) {
getContentResolver().unregisterContentObserver(mContentObserver);
}
}
};
}
Aggregations