0

I have an Android mobile application that consumes a WCF REST service that sends back an arbitrarily massive amount of data. The service sends this data in chunks. At the end of a chunk there is an indicator that states there is more and if that indicator is passed back to the service the next chunk is sent.

This data gets put into a ListView in the application. What I want to do is have the calls to the service loop and use a handler to update the listview as the data comes.

I have a couple questions:

Do I need to loop the AsyncTask or loop within the AsyncTask?

and

Would it be best to update the ListView as the data comes in or get all the data and then update the ListView with all the data?

Any answers to these questions or insight into this process would be appreciated.

SmashCode
  • 4,227
  • 8
  • 38
  • 56

1 Answers1

0

-AsyncTask is more meant for quick one-off operations. Inserting some records into a database, sending a query, firing a short HTTP request (say, to ping a server). It's not really meant for longer processes like downloading large amounts of data from a server. In this particular case I'd skip the AsyncTask and just create a background worker thread. Send the thread a wakeup call when there's work to do, let it sleep the rest of the time.

-Whether it's best to update your listview incrementally or all-at-once can vary with the type of application, but often it's a better experience to update incrementally, so the user has some sense of progress.

Alexander Lucas
  • 22,171
  • 3
  • 46
  • 43
  • Do you know what the handler would like for this? – SmashCode Apr 09 '12 at 17:42
  • The Handler/Thread/Runnable for loading data has already been discussed on SO. Here's a link: http://stackoverflow.com/questions/6960020/android-loading-data-from-the-web-in-background-thread-with-a-progress-gui – Alexander Lucas Apr 09 '12 at 18:00