Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
452 views
in Technique[技术] by (71.8m points)

android - First time error loading picture with Picasso

I have an Activity with an ImagePagerAdapter (extends of FragmentStatePagerAdapter) that has this getItem method:

@Override
        public Fragment getItem(int position) {
            Log.d(LOGTAG, "------------>mUserPicturesList.get("+position+").getFilename(): " + mUserPicturesList.get(position).getFilename());
            return UserDetailFragment.newInstance(mUserPicturesList.get(position).getFilename());
        }

The fragment that is instantiated has this onCreateView:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate and locate the main ImageView
    final View v = inflater.inflate(R.layout.image_detail_fragment, container, false);
    mImageView = (ImageView) v.findViewById(R.id.imageView);
    mProgressPicturePager = (ProgressBar) v.findViewById(R.id.progress_picture_pager);

    String imageUrl = WApp.PHOTO_URL + mImageUrl + "?type=user_gallery_big_img";

    Picasso picasso = Picasso.with(getActivity());
    picasso.setDebugging(true);
    picasso.load(imageUrl)
            .placeholder(R.drawable.no_picture_man_big)
            .error(android.R.drawable.stat_notify_error)
            .into(mImageView, new Callback() {
                @Override
                public void onSuccess() {
                    mProgressPicturePager.setVisibility(View.GONE);
                }

                @Override
                public void onError() {
                    Log.d(LOGTAG, "picasso load error");
                    mProgressPicturePager.setVisibility(View.GONE);
                }
            });

    return v;
}

The Problem:

When the ImagePager load first time, some times, Picasso call onError, showing the .error drawable. If I press on back button and go back to the Activity that has the ImagePager, Picasso load the picture correctly. If the ImagePager has two or more pictures and I swipe between the pictures, those are loaded correctly some times without exit and reenter to the ImagePager.

The Theories:

I think that it could be a problem of cache, but after many searches, I bet that the problem is in the weak reference of the Picasso. Keep in mind that the problem only appears the FIRST TIME I load the activity that have the ImagePager.

In another place, currently Picasso works fine in listView with an adapter loading the pictures at first time. Calling Picasso inside the getView method of Adapter class.

Visited links

Thanks in advance.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The problem was solved in the Picasso 2.3.0.

The fix is in the Picasso changelog:

Requests will now be automatically replayed if they failed due to network errors.

I hope this save you many hours.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...