Picasso Image Caching
Solution 1:
I've researched some more into your questions and decided that I should publish this as an answer rather than a comment.
- Yes - Picasso loads images asynchronously so making repeated calls will cause images to be downloaded in parallel.
- Yes - just make the call as normal and Picasso will handle the re-use of downloaded images e.g. in Activity1, call
Picasso.with(this).load("image1");and, later, make a call to the same URL in Activity2. The image will already be cached (either in memory or on device storage) and Picasso will re-use it, rather than downloading it again. - Yes - see above (Picasso will automatically use cached images where available)
This does not seem to have such a clear-cut answer. One thing you can do is provide an image to display if an error occurs while fetching the real image:
Picasso.with(context) .load(url) .placeholder(R.drawable.user_placeholder) .error(R.drawable.user_placeholder_error) .into(imageView);The 'placeholder' will be displayed whilst the attempt is being made to fetch the image from the web; the 'error' image will be displayed, for instance, if the URL is not valid or if there is no Internet connection.
Update, 17/03/2014:
Picasso supports the use of a callback to report you of a failure. Modify your usual call (e.g. the above example) like so:
.into(imageView, new Callback() { @Override public void onSuccess() { // TODO Auto-generated method stub } @Override public void onError() { // TODO Auto-generated method stub } });
In conclusion, it sounds like Picasso would be a great choice of library for you. It definitely makes image downloading very quick and very easy, so I like it a lot.
Post a Comment for "Picasso Image Caching"