Hello! There are 12 ImageViews in my activity, and I uploaded images to them. But, alas, in order to avoid OutOfMemory, I had to severely cut the size of the pictures.

About this resource - http://developer.android.com/intl/ru/training/displaying-bitmaps/load-bitmap.html I know, but they say that when you need to load a large number of images, you need to use this method (which is described on the link) in AsyncTask. But I can not imagine how to do it.

Please explain or, if it is not difficult for you, write an example of how to implement it. Thank you in advance!

  • Do you have all the pictures on one screen or is it a list? - Yuriy SPb
  • Not in the list, but in one activity. Tile arranged, to be exact. - Crok

1 answer 1

AsynkTask will only help you upload pictures in another thread. It is advisable, because loading a large number of images is a heavy code that, when executed in the main thread, will result in ANR. From OutOfMemory, AsynkTask will not save you.

You need to use the Glide library - it compresses the images to the desired size, minimizing the memory occupied and, of course, it will do it in another thread. This, too, really will not save you from OutOfMemory, but the probability of its occurrence will be an order of magnitude lower

  • AsyncTask has three methods: doInBackground, onPreExecute and onPostExecute. Which of them should be used in this situation? - Crok
  • No, they are all useless - P. Ilyin