The default Gallery widget on Android does not recycle views - everytime the view for a new position is called the widget always calls the getView
method of the adapter with convertView
set to null.
As you scroll backwards and forwards this ends up in lots of views being created, which the recycler component that the Gallery stores them in does not seem to recycle them quickly enough leading to an OOM situation.
You can test this easily with a few large-ish images as your gallery items, but just a TextView will cause it in the end. Put a log statement with a counter in the getView
method of your adapter also to see how many new views are created.
Does a third-party widget which behaves like a Gallery but that also implements view recycling exist?
Gallery
, modify it to suit, and use it. I see in the code what you're referring to. I have no idea whymakeAndAddView()
is written the way it is. – Quenchless