2

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));
AVEbrahimi
  • 17,993
  • 23
  • 107
  • 210

2 Answers2

4

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.

welshk91
  • 1,613
  • 18
  • 16
  • Since Picasso 2.5.0 OkHttpDownloader class has been changed, assuming you are using OkHttp3 (and so picasso2-okhttp3-downloader), so you have to do something like this: – Mostafa Imani Jan 10 '21 at 06:41
3

You have two options:

  1. Subclass a Downloader class. Check this for reference implementation
  2. Preconfigure OkHttpClient with timeouts and pass it to Picasso
bhargavg
  • 1,383
  • 9
  • 12