AVEbrahimi
AVEbrahimi

Reputation: 19164

Loading images using picasso on a slow connection

I am using Picasso to load images for a listview. The problem is internet connection is slow. How can I change load timeout time in Picasso?

My code is :

Picasso.with(context)
.load(MainActivity.WEBSITE + book_item.Image)
.resize(final_thumb_width, final_thumb_height)
.into(new PicassoTarget(book_item,item.img, item.title));

Upvotes: 3

Views: 7418

Answers (2)

welshk91
welshk91

Reputation: 1663

You could possibly try something like this in your MainActivity's onCreate (or whereever you want to create the Picasso Builder

    Picasso picasso;
    OkHttpClient okHttpClient;

    okHttpClient = new OkHttpClient();
    okHttpClient.setConnectTimeout(10, TimeUnit.SECONDS);

    picasso = new Picasso.Builder(this)
            .downloader(new OkHttpDownloader(okHttpClient))
            .build();

That should give Picasso a timeout of ten seconds. Configure it to your needs.

Full Disclosure: I don't use a timeout. I just noticed this in the API. This may be completely wrong lol.

Upvotes: 4

bhargavg
bhargavg

Reputation: 1379

You have two options:

  1. Subclass a Downloader class. Check this for reference implementation
  2. Preconfigure OkHttpClient with timeouts and pass it to Picasso

Upvotes: 2

Related Questions