Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Endless list memory management

Tags:

I'm implementing an endless listview by loading more items to the arraylist in the onScrollStateChanged(...) method. If I'm implementing this scheme for fetching more than 1 million entries, I will have a million objects added to the arraylist, which is memory intensive. What schemes can I use for efficient memory management ?

PS: The question is about the number of items that can be put into the adapter. Edit:

More details:

The source of the data is Internet. I have to fetch the data from the Internet and put it into the listview adapter.

like image 975
user3388324 Avatar asked Mar 10 '14 09:03

user3388324


2 Answers

I think you should just keep the current entries and the one just before or after them(maybe 100),put this data to a cache.

When you scroll your listview,fetch more entries and update the cache as before(do not get 1 million at one time).

like image 156
tianwei Avatar answered Oct 05 '22 04:10

tianwei


In Android the ListView is virtualized. Practically that means that there's no actual limit for number of elements inside it. You can put millions of rows inside the list, it'll only allocate memory for the currently visible ones (or a few more tops).

Source

Also check this article Performance Tips for Android’s ListView

like image 37
fida1989 Avatar answered Oct 05 '22 04:10

fida1989