2

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.

Community
  • 1
  • 1
wendigo
  • 1,973
  • 2
  • 17
  • 21
  • Have you attached a listener to your Picasso instance? You can print the stacktrace and see what the error was. Also what version of Picasso is this on? – dnkoutso Apr 13 '14 at 19:13

1 Answers1

1

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.

wendigo
  • 1,973
  • 2
  • 17
  • 21
  • I tried to update to the latest version of Picasso 2.3.2 in Android Studio v0.8.2 but it fails to sync the gradle project saying `Error:Failed to find: com.squareup.picasso:picasso:2.3.2`. How do you fix this? – Etienne Lawlor Jul 18 '14 at 07:03
  • @toobsco42 try this line: `compile group: 'com.squareup.picasso', name: 'picasso', version: '2.3.+'` – wendigo Jul 18 '14 at 10:28
  • I found out it was an issue with permissions for files to be moved or deleted. After fixing permission on the appropriate folders and cleaning the project then it all works now. – Etienne Lawlor Jul 19 '14 at 09:01