From 57114217840217829590c660e163e3f63c5e451a Mon Sep 17 00:00:00 2001 From: Anthony Restaino Date: Sat, 27 Aug 2016 15:42:16 -0400 Subject: [PATCH] Fixed a threading bug in ImageDownloadTask --- .../lightning/async/ImageDownloadTask.java | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/acr/browser/lightning/async/ImageDownloadTask.java b/app/src/main/java/acr/browser/lightning/async/ImageDownloadTask.java index 339e4f4..c63ab2f 100644 --- a/app/src/main/java/acr/browser/lightning/async/ImageDownloadTask.java +++ b/app/src/main/java/acr/browser/lightning/async/ImageDownloadTask.java @@ -10,6 +10,8 @@ import android.support.annotation.NonNull; import android.util.Log; import android.widget.ImageView; +import com.anthonycr.bonsai.Schedulers; + import java.io.File; import java.io.FileOutputStream; import java.io.InputStream; @@ -146,17 +148,12 @@ public class ImageDownloadTask extends AsyncTask { final Bitmap fav = Utils.padFavicon(bitmap); final ImageView view = mFaviconImage.get(); if (view != null && view.getTag().equals(mWeb.getUrl().hashCode())) { - Context context = view.getContext(); - if (context instanceof Activity) { - ((Activity) context).runOnUiThread(new Runnable() { - @Override - public void run() { - view.setImageBitmap(fav); - } - }); - } else { - view.setImageBitmap(fav); - } + Schedulers.main().execute(new Runnable() { + @Override + public void run() { + view.setImageBitmap(fav); + } + }); } mWeb.setBitmap(fav); }