public void loadImage(Object data, ImageView imageView) { if (data == null) { return; } if (cancelPotentialWork(data, imageView)) { final ImageAsyncTask task = new ImageAsyncTask(this, imageView); imageView.setImageDrawable(new AsyncDrawable(mResources, mLoadingBitmap, task)); // task.execute(data); task.executeOnExecutor(AsyncTask.DUAL_THREAD_EXECUTOR, data); } }
public static boolean cancelPotentialWork(Object data, ImageView imageView) { final ImageAsyncTask task = getImageAsyncTask(imageView); if (task != null) { final Object bitmapData = task.getData(); if (bitmapData == null || !bitmapData.equals(data)) { task.cancel(true); } else { return false; } } return true; }