I use Picasso to load images in the navigation view. When downloading images from an Internet, navigationview quickly picks up the picture substitutes where you want. No problems. But if I specify the choice of pictures from the local storage, I mean from the SD card, then the navigationview starts to slow down. Even gives such an error.

Throwing OutOfMemoryError "Failed to allocate a 23970828 byte allocation with 16777216 free bytes and 22MB until OOM" 

It turns out that the trouble with memory. Tell me how to solve the problem?

  • Do you specify a direct link, Without using Picasso? - Chaynik

1 answer 1

Yes, you have the OOM log, if you specify a local image without using different лоадеров , then this is quite real. Load images in the same way through Picasso , but use resize . Below is a link to an example of how to do this. This will save you both from OOM and from brakes.

https://futurestud.io/blog/picasso-image-resizing-scaling-and-fit

  • Thanks for the info. Then the question is - how to determine the size of a picture on various devices using resize? After all, there resize is specified in pixels - Ivan Vovk
  • Take the height and width of the ImageView, as soon as they become known, you can substitute them. - Chaynik
  • Resize helped - all the brakes were gone, but now (having tried all the parameters from this article) the image is blurry. Without resize the image was clear. So it should be, or am I missing something? - Ivan Vovk
  • It depends on what size you take =) If you take them in pixels not from imageView.getHeight (), but an equivalent figure (for example, in xml image view has a size of 126dp and width 320dp) and you specify the same numbers for resize (126, 320 ), then on high-density screens it will be blurred, if you specify with similar numbers, you need to convert the numbers specified in resize to pixels. (dpToPx) stackoverflow.com/a/17410076/2667883 - Chaynik