Well, so far I have noticed that two options for a real app that wants to show a photo gallery composed of images that exist on a server are: volley and picasso. There are many useful tutorials about them like this available on Internet. But, my problem is that why should I use them at all? Is anything wrong with just using the URLs of the images in our ImageView
s?
Edit: in compliance with CommonsWare's comment my question is that why we don't simply use ImageView.setImageURI or methods like that?
There is no means of directly handing a URL to an ImageView
. The closest thing is setImageURI()
, and that has three problems:
I don't think it handles HTTP at all
Even if it did, as the docs for that method indicate, it does so on the main application thread, causing you to crash with a NetworkOnMainThreadException
Even if you use some script-kiddie approaches to block that exception, your UI will be frozen while the download is proceeding
The #1 reason to use an image loading library is to get the image loading work done on background threads, updating the ImageView
(or NetworkImageView
in Volley's case) when the image is ready. Many of these libraries offer additional useful features, outlined in the blog post that you linked to and in other answers here.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments