Im using RecyclerView to display a list containing an imageView. To make the UI more fluently, I load 58dp thumbnails saved on sd card into these i
You should cancel the old request before starting a new one, but regardless of cancelling you can still show the wrong image if both images loaded more or less at the same time on the same container/view holder that has been recycled (happens easily with fast scroll and small images).
The solution is to:
Example loading icons from apps in background with RxJava:
public void loadIcon(final ImageView appIconView, final ApplicationInfo appInfo, final String uniqueAppID) {
Single.fromCallable(() -> {
return appIconView.getContext().getPackageManager().getApplicationIcon(appInfo);
})
.subscribeOn(Schedulers.computation())
.observeOn(AndroidSchedulers.mainThread())
.subscribe( drawable -> {
if (uniqueAppID.equals(mUniqueAppID)) { // Show always the correct app icon
appIconView.setImageDrawable(drawable);
}
}
);
}
Here mUniqueAppID is a field of the view holder changed by onBindViewHolder