Reputation: 2615
I was trying to load lots of thumbnails into a GridView, but it ended up in an OutOfMemoryException. I want to load about 500-1000 (or even more) images into the GridView and I plan to use MINI_SIZE thumbnails. Now I'm asking what an ideal and low-performance approach to that would be.
Upvotes: 0
Views: 78
Reputation: 3913
This is where RecyclerView
comes into the picture.
What is a RecyclerView?
It's like a ListView in which your android system will automatically recycle those views which are not visible on the screen anymore. It allows the user to scroll(vertically and horizontally) between the views and it maintains it's own cache. What `automatically recycling" means here is that it maintains a threshold of "not-anymore visible views" and then re-uses those views which have passed the threshold limit.
Hmm! But how will you load so many images, won't it cause an ANR?
There are two approaches to fix this problem:
HandlerThread
or AsyncTask
or simply a Thread
to load all the items at once and show a ProgressBar
until you are done loading. But this approach can cause OOM (Out Of Memory)
in some devices.Also, don't forget to use Glide for caching images.
Upvotes: 1
Reputation: 13129
To load the images use a background thread like an AsyncTask
and use a Recyclerview
with a GridLayoutManager
that should load the images as you are dragging and not all at once
Upvotes: 1