Picasso Image Caching

I want to download the following image upload code with Picasso image cache.

DownloadImage downloadImage = new DownloadImage(); 
downloadImage.execute(advert.getImgUrl());

private class DownloadImage extends AsyncTask<String, Void, Bitmap> {

    @Override
    protected Bitmap doInBackground(String... arg) {
        Bitmap bmp = null;
        try {
            URL url = new URL(arg[0]);
            bmp = BitmapFactory.decodeStream(url.openConnection()
                    .getInputStream());

        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
        return bmp;

    }

    @Override
    protected void onPostExecute(Bitmap result) {
        if (result == null) {
            Intent intent = new Intent(AdvertisingActivity.this,
                    AdvertisingErrorActivity.class);
            intent.putExtra("ad-error", "Error downloading image");
        }
        adImg.setImageBitmap(result);
        super.onPostExecute(result);
    }
}

I have a few questions regarding this.

  • I want to upload multiple images in parallel. If I repeat calls Picasso.with(getActivity()).load(url);with different URL values, is this done?

  • I want to upload images to one activity and use it in another action. Is it possible? How can I do that?

  • If I call Picasso.with(getActivity()).load(url);more than once with the same URL value, does it load cached images for subsequent calls after loading the image?

  • If the image upload process is not possible for some reason, can you tell Picasso about the error?

+4
1

, , .

  • - Picasso , .
  • - , Picasso , . Activity1 Picasso.with(this).load("image1"); , , URL- Activity2. ( , ), Picasso , .
  • - . (Picasso , )
  • , , . , , , :

    Picasso.with(context) .load(url) .placeholder(R.drawable.user_placeholder) .error(R.drawable.user_placeholder_error) .into(imageView);

    "placeholder", ; "" , , URL- .

    , 17/03/2014:

    Picasso . (, ) :

    .into(imageView, new Callback() {
        @Override
        public void onSuccess() {
            // TODO Auto-generated method stub    
        }
    
        @Override
        public void onError() {
            // TODO Auto-generated method stub
        }
    });
    

, , Picasso . , .

+11

Source: https://habr.com/ru/post/1530609/


All Articles