1

I am loading around 5-10 images through Picasso in a new Target and then using it to place custom markers or GroundOverlay images on Google Map.

The problem is the number of images being loaded is not consistent. It varies between all images getting loaded to partial images loading to none of the images loading in the Bitmap.

onPrepareLoad gets called when a particular image is not loading.

while (count<ts_news_data_id.size()){
        int index = il_id_data.indexOf(mainMarkers.get(count));
        Log.d("tag_picasso","Picasso");
        loadPicasso(il_lat_data.get(index),il_long_data.get(index),count);
        count++;
    } 

loadPicasso method

private void loadPicasso(final Double lat, final Double lng, Integer count){

    Target target = new Target() {
        @Override
        public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
            Log.d("tag_bitmap_load","Bitmap Loaded");
            getRoundedShape(bitmap, lat,lng);
        }

        @Override
        public void onBitmapFailed(Drawable errorDrawable) {
            Log.d("tag_bitmap_fail","Bitmap Failed");
        }

        @Override
        public void onPrepareLoad(Drawable placeHolderDrawable) {
            Log.d("tag_bitmap_prepare","Bitmap Prepare");
        }
    };

    Picasso.with(getApplicationContext())
            .load(ts_news_data_image.get(count))
            .resize(100,100)
            .centerCrop()
            .into(target);
}

getRoundShape takes care of further customizes the loaded bitmap and then adds a marker or ground overlay on the Google Map.

What should I do to make sure all images load every time?

user3884753
  • 255
  • 6
  • 16
  • Possible duplicate of [Picasso Load Image into Target](https://stackoverflow.com/questions/38617505/picasso-load-image-into-target) – ADM May 04 '18 at 14:50
  • Picasso holds a `WeakReference` to target . Thats the reason you are not getting callback . You can use the b above solution or you can Try Glide. I am not sure if Glide follow the same approach or not . – ADM May 04 '18 at 14:52
  • @ADM Based on the above solution I will have to create a new Target for each image? – user3884753 May 04 '18 at 14:58
  • Yeah sort of . Figure out a way to not use a Target . I see you are creating Rounded image after `Bitmap` load . You can use a [CircleImageView](https://github.com/hdodenhof/CircleImageView) to directly load . Or you can use [picassotransformations](https://github.com/wasabeef/picasso-transformations) for custom transformations. If that does not fit your requirement Try Glide. – ADM May 04 '18 at 15:01
  • @ADM Hey, I have kept a strong reference to Target as suggested. Still the problem is persisting. – user3884753 May 05 '18 at 07:20

0 Answers0