For various Android apps, I need big ListViews, i.e. such representations with 100-300 elements.
All records must be loaded in bulk when the application is running, as some sorting and processing is required, and the application cannot know which items should be displayed first, otherwise.
So far, I have also uploaded images for all the elements in the array, which are then stored in ArrayList<CustomType>along with the rest of the data for each record.
But, of course, this is not a good practice, since you will most likely have OutOfMemoryException: Links to all images in the ArrayListgarbage collector do not allow.
So the best solution, obviously, is to download only text data in bulk, while images are then loaded as needed, right? The Google Play application does this, for example: you can see that images are loaded when scrolling to them, i.e. They are probably loaded into the adapter method getView(). But with Google Play, this is a completely different problem, since the images must be downloaded from the Internet, which is not suitable for me. My problem is not that loading images takes too much time, but it takes too much memory to store them.
So what should I do with the images? Upload to getView()when you really need them? Would make the scroll listless. So, is it called AsyncTask? Or just normal Thread? Parameterize it?
I could save the images that are already uploaded to HashMap<String,Bitmap>so that they do not need to be uploaded again to getView(). But if this is done, you will again have a memory problem: it HashMapstores links to all images, so in the end you can have it again OutOfMemoryException.
I know that there are already many questions that discuss the "lazy loading" of images. But they mainly cover the problem of slow loading, and not too much memory consumption.
Edit: Now I decided to run AsyncTasks in getView (), which loads the image into the ListView in the background . But this causes my application to run as a RejectedExecutionException. What should I do now?