I use Picasso library. And ran into problems and errors:
E / Bitmap ﹕ createBitmap error!
Code example:
Picasso .with(this) .load(object.getImages([1]) .error(R.drawable.video_cap) .into(exVideo); At first, everything works, but later (when I look at the second circle) the crash of "Out of memory" comes out. I used the fit() and resize() methods - the application runs longer, but ends the same way.
Having processed the error:
try { Picasso.with(this) .load(object.getImages([1]) .error(R.drawable.video_cap) .into(exVideo); } catch (OutOfMemoryError e) {} application no longer crashes. But the photos are no longer loaded and the application starts to slow down. As I understand it, Picasso took all the RAM and there is no more space for new photos.
I need to somehow erase photos from RAM to display new ones.
Using memoryPolicy(MemoryPolicy.NO_CACHE) will not work. I cache the photos on the SD card by writing this code in the Application class:
Picasso.Builder builder = new Picasso.Builder(this); builder.downloader(new OkHttpDownloader(this,Integer.MAX_VALUE)); Picasso built = builder.build(); Picasso.setSingletonInstance(built); I keep links to pictures in the database, and Picasso then successfully loads them.
So I have 3 questions:
- how to free up space in RAM for new pictures
- how to cache only the right pictures on the SD card, not all
- how to handle the error "E / Bitmap ﹕ createBitmap error!"
By clicking on the button, I upload new images
if (object.getImages().length > 1) { try { Log.e("test", "load picasso 1"); Picasso.with(this).load(object.getImages()[1]).fit().tag("tag1").error(R.drawable.video_cap).into(exVideo); }catch (OutOfMemoryError e) { Log.e("test", "error 1" + e); Picasso.with(this).load(object.getImages()[1]).fit().memoryPolicy(MemoryPolicy.NO_CACHE).into(exVideo); }catch (Exception e){ Log.e("test", "error 11" + e); } }