after some advice really. My app fills a list view on load using a mediastore cursor. This is pulling music linked to user defined folder, which in most cases will be all of their stored music. I have one beta tester that is using an Archos Tablet with approximately 10000 songs on it, running android 2.2. While performance for most users is pretty slick, I wanted to improve the experience for users such as this.
The current process:
User loads app.
App finds default folder
App populates list view with music within and below that folder
User moves to a folder further down the tree, list view is repopulated based on the selected folder
User moves again….list is repopulated based on the selected folder…
So what I’m wondering is this – is it faster/more efficient to use the following process:
User loads app
App finds default folder
app populates list view with music within and below that folder
user moves to a folder within the tree, THE LIST IS FILTERED TO THAT FOLDER
if the user moves higher up the tree than the default data (i.e. potential for new files), the list view is repopulated, but only in this circumstance.
So basically,my questions is “how does filtering compare to repopulation?”
A very good question. Let me try to answer this.
Filtering is actually repopulation the
ListView, whereas you create/get a new collection and tell theAdapterit’s content has changed by callingnotifyDataSetChanged.The ‘heavy’ work for a listView is that
getViewcall in it’s adapter. I’ve tested this myself, and if you inflate a new View every time getView is called, the performance drops. Heavenly.The ListView’s adapter is built so that already inflated views can be re-used, which tackles above named problem. Besides, only visible views are loaded, so it’s not like the
Adapteris going to create 10000 views if you tell it’s collection is 10000 items big.notifyDataSetChangedwill tell the adapter to rebuild the listviews content, but it still contains previously inflated views. So here is a big performance win.So my advice for you is, when you are using the same ‘row layout’ to just repopulate the
ListViewusingnotifyDataSetChanged. I’ve implemented this multiple times myself without noticing any UI performance issues. Just make sure to do the filtering of your collection an a background thread. (AsyncTaskcomes in handy here).One last tip: Do you have any phone thats quite old? Or someone you know does? Find the slowest phone you can and test your application on it for performance. I have a HTC Legend myself, which is outdated and slow if f*ck, but perfect for performance testing. If it runs on my (old) phone, it runs on any phone.
Pseudo code sample if your applications flow: