1

I am facing an issue with Glide

You cannot start a load for a destroyed activity

I don't see this crash I just reported that this happens, then I checked my code and I saw I wrote :

public static void setImageWithGlide(Context context, String imageUrl, ImageView imageView) {
    if (context != null && imageView != null)
        Glide.with(context).load(imageUrl)
                .dontAnimate().into(imageView);
}

So, I did some reading and saw people are using

1 - Context , as i did

2 - `Application Context', which not good idea at all for many reasons

3 - Getting context from the View itself so in my case it will become :

public static void setImageWithGlide(String imageUrl, ImageView imageView) {
    if (imageView != null && imageView.getContext() != null)
        Glide.with(imageView.getContext()).load(imageUrl)
                .dontAnimate().into(imageView);
}

I don't know if this will solve the problem but why this way of getting context is not popular? what is the reason not to use it? it also saves me the context passing to the method (Which for me personally is not that good because I do like to know that this method using context, which I know when I passing it)

so...

1 . When is the right and wrong cases to get Context from view? 2 . Do you think there is a better way to solve this issue with glide?

By the way, I don't think user seeing this crash it may be handled inside Glide.

Shubham Jain
  • 2,365
  • 2
  • 17
  • 29
Jesus Dimrix
  • 4,378
  • 4
  • 28
  • 62

1 Answers1

0

According to this: https://android.jlelse.eu/using-glide-few-tips-to-be-a-pro-60f41e29d30a it is recommended to use the current activity context for glide And view.getContext() returns the activity's context (maybe most of the times). So just easily use that for glide

navid
  • 1,022
  • 9
  • 20