This is an APP with some sort of gallery context. Using REST , I get (Volley) JSON, which contains information about the place and some links to images. Because there are about 60 places, itβs not enough to cache the PICASSO form. The data is stored in the database, so I decided to include the image in the database as a byte stream . This was done, but not as good as shown below. Code inside AsyncTask .
@Override protected Bitmap doInBackground(Void... params) { try { return Picasso.with(context) .load(site.getImageURL()) .get(); } catch (IOException e) { e.printStackTrace(); } return null; } @Override protected void onPostExecute(Bitmap bitmap) { super.onPostExecute(bitmap); ByteArrayOutputStream stream = new ByteArrayOutputStream(); try { bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream); } catch (Exception e) { e.printStackTrace(); } site.setImageBytes(stream.toByteArray()); db.openForWrite(); db.updateSite(site.getId(), site); db.close(); }
My question is how to make it effective, do you know it is better to do it? I tried callback in Picasso to add an image to DB onSuccess , but this requires a representation as the first argument.
Perhaps there are good ways to save images to an SD card and replacing the HTTP link with the image location on the SD card.
Or direct image caching to disk?
source share