Why does Picasso running in a background thread block onActivityResult?

☆樱花仙子☆ 提交于 2019-12-04 17:08:49

Looking at your code you are creating a new thread when you don't need to. Picasso has a configurable executor method for threading.

I had an issue when loading over 100+ images using picasso and it would lock up and block the UI Thread on me but this was due to it creating a new Thread every time I called picasso to get an image. I solved this by doing a little research and found that within picasso there is a configurable executor method.

This is my ImageHandler class implementation

public class ImageHandler {

private static Picasso instance;

public static Picasso getSharedInstance(Context context)
{
    if(instance == null)
    {
        instance = new Picasso.Builder(context).executor(Executors.newSingleThreadExecutor()).memoryCache(Cache.NONE).indicatorsEnabled(true).build();
        return instance;
    }
    else
    {
        return instance;
    }
}
}

I don't know that this is your issue, but it would be worth a try if you haven't implemented it yet.
Here is the way I use it to load images

    ImageHandler.getSharedInstance(getApplicationContext()).load(imString).skipMemoryCache().resize(width, height).into(image, new Callback() {
        @Override
        public void onSuccess() {
            layout.setVisibility(View.VISIBLE);
        }

        @Override
        public void onError() {

        }
    });
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!