From bde2220d91774337fba60cfdcc4324005b878736 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Sat, 18 Apr 2020 11:34:43 +0800 Subject: Remove unused attributes. Fix loading images using GlideImageGetter after the activity is destroyed. --- .../infinityforreddit/Utils/GlideImageGetter.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'app/src/main/java') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/GlideImageGetter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/GlideImageGetter.java index 8e018449..04c16284 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/GlideImageGetter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/GlideImageGetter.java @@ -1,5 +1,7 @@ package ml.docilealligator.infinityforreddit.Utils; +import android.app.Activity; +import android.content.Context; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.drawable.BitmapDrawable; @@ -53,10 +55,13 @@ public class GlideImageGetter implements Html.ImageGetter { BitmapDrawablePlaceholder drawable = new BitmapDrawablePlaceholder(textSize); - container.get().post(() -> Glide.with(container.get().getContext()) - .asBitmap() - .load(source) - .into(drawable)); + Context context = container.get().getContext(); + if (!(context instanceof Activity && ((Activity) context).isFinishing())) { + container.get().post(() -> Glide.with(context) + .asBitmap() + .load(source) + .into(drawable)); + } return drawable; } -- cgit v1.2.3