Skip to content Skip to sidebar Skip to footer

Fetch Images With Callback In Picasso?

I want to show a photo series with no gaps in-between the photos, where photos change in a regular interval. I realized Picasso initializes the ImageView before it starts downloadi

Solution 1:

Based on the source, it looks like fetch does nothing upon completion, including notifying any potential listeners. Unfortunately, FetchAction isn't a public class, so you can't override this functionality either.

You can workaround this problem by using a custom Target subclass, like this:

Picasso.with(getContext()).load(url).into(new Target() {
    @Override public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
        // cache is now warmed up
    }
    @Override public void onBitmapFailed(Drawable errorDrawable) { }
    @Override public void onPrepareLoad(Drawable placeHolderDrawable) { }
});

Solution 2:

I know this is an older question but the fetch() command allows for callbacks such as fetch(Callback callback). This has an onSuccess() and onError() callback for the requested URI load.

See here for javadoc details

Solution 3:

The .into() method provides a second argument which is a callback to success and failure. You can use this to keep track of when an image has arrived.

Javadoc: http://square.github.io/picasso/javadoc/com/squareup/picasso/RequestCreator.html#into-android.widget.ImageView-com.squareup.picasso.Callback-

Have a look at this: How to implement my own disk cache with picasso library - Android? Jake Wharton himself has an answer there.

Solution 4:

As of version 2.7 of Picasso, it does support callback with the fetch() method.

Picasso.get()
                    .load(url)
                    .fetch(new Callback() {
                        @Override
                        public void onSuccess() {
                            //Success
                        }
                        @Override
                        public void onError(Exception e) {
                            //Error
                        }});

Solution 5:

I tried noPlaceholder method to resolve the problem. I have tried many methods, but eventually found that the question is to make the previous picture wait for next picture.

Post a Comment for "Fetch Images With Callback In Picasso?"