androidtimeandroid-glideimage-loading

How to stop loading an image in Glide if it takes a long time to load?


It is critical for me that the picture is loaded for a certain time, if during this time it cannot be loaded, then I want to stop loading and move on to the next function.

It seems that here it is necessary to somehow throw an exception, but an important condition is the time for loading the picture, which I can regulate myself.

I think this logic should be here

onLoadFailed

but maybe here

onResourceReady

Let me please know if anyone has come across this issue.


Solution

  • You can set a timeout as described in the documentation:

    Glide.with(context)
      .load(url)
      .option(MyCustomModelLoader.TIMEOUT_MS, 1000L)
      .into(imageView);