I have a scenario where i have to do following task:
1. populate a list-view.
2. perform database operation which is very time consuming task.
3. database processing/operation time is sometime unpredictable.
I have used listView using holder pattern, now it is working faster than earlier but still taking significant time. What else i can do to improve the performance.
I have an idea but i am afraid whether it will be good to implement or not. Idea is to put the database operation in AsyncTask and update my listview there only.
But i am afraid of doing so is because my listview is totally dependent on database result. So i can display something on Listview only when i am done with DB operation
Please suggest is using Async task will be good approach and please suggest any other idea.
Using the Holder approach is good. Use that in your adapters always. Make sure you are reusing the convert views as well.
Using an
AsyncTaskis the best option. But you don’t have to wait for the entire operation to complete. Read up on howAsyncTaskworks. Use thepublishProgress()method in yourdoInBackground()of theAsyncTaskto give batches of data to your list.For example, if you have to process 100 rows, process 10, then do a
publishProgress()which will update the list with those 10 rows. When you process the next batch, update the list withpublishProgress()again.