Picasso java.lang.IllegalStateException: Method call should not happen from the main thread

后端 未结 5 2036
后悔当初
后悔当初 2021-01-07 22:32

I am attempting to use Picasso to get three Bitmap images from a URL

public void onCreate(Bundle savedInstanceState) { 
  super.onC         


        
5条回答
  •  旧巷少年郎
    2021-01-07 23:12

    Just for the record:

    Picasso.with(context).load(url).into(new Target() {
        @Override
        public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
            Log.i(TAG, "The image was obtained correctly");
        }
    
        @Override
        public void onBitmapFailed(Drawable errorDrawable) {
            Log.e(TAG, "The image was not obtained");
        }
    
        @Override
        public void onPrepareLoad(Drawable placeHolderDrawable) {
            Log.(TAG, "Getting ready to get the image");
            //Here you should place a loading gif in the ImageView
            //while image is being obtained.
        }
    });
    

    Source: http://square.github.io/picasso/

    onPrepareLoad() is called always after starting the request. from can be "DISK", "MEMORY" or "NETWORK" to indicate where was the image obtained from.

提交回复
热议问题