I am loading an image with Glide, as follows.
Glide.with(myActivity.this).load(url1).diskCacheStrategy(DiskCacheStrategy.ALL).into(avatarImageView);
It turns out that sometimes it fails me, since sometimes the url1 doesn't exist, and I have to load a url2 . (url1 and url2 is a String that corresponds to the URL of the image)
I want to know how to retry with url2 if url1 fails...
Thank you!
EDIT: url1 and url2 are not null or empty. They have different formats when they were created and I should try one format first and if it doesn't load then try the other format.
Example:
String url1= "http://www.foto.xd/juan_perez_123456.jpg";
String url2= "http://www.foto.xd/123456.jpg";
You can use the Glide callback and handle the error, in case the first image gives you an error, you reload it with Glide...
What you need is a callback that determines if the url load failed, based on this load another image.
If an error is found you can use .error() and define an image of your resources.
But in this case you want to load on error another image via a url, so you can load the image inside
onException()
which is called if an error occurred loading the first image:For more information you can see the official documentation .