0

In my application, when user presses Sync button (calls function onSynchronize()), I need to do the following activities:

  1. form url for data synchronization based on user's preferences
  2. download url
  3. parse data received
  4. for each item found in data download picture (another url)
  5. update ListView with data downloaded and parsed

What is the best approach to split this activity between classes? Since steps 2-4 should be done in background (ASyncTask), and the same steps 1-4 will be used in the service (for automatic synchronization).

Should I put step 5 in onPostExecute of according ASyncTask? Or, should I put there steps 3-5? What is the most logical and clear approach?

LA_
  • 19,823
  • 58
  • 172
  • 308
  • As of now I created the following function (but within main class, which is not very good): String formUrl(), String getFilmsBrowse(url); void parseFilmsBrowseAndDBUpdate(jsonString). All of them are started in AsyncTask. – LA_ Mar 26 '11 at 12:59

1 Answers1

0

First, you need an Adapter class for your ListView. Also you'll need a parser class(you can implement SAX or DOM if response is XML). Take a look at Lazy load of images in ListView to understand image downloading into ListView. Your parser class can return an array of custom objects and then you'll supply it to listview via your custom adapter class.

Community
  • 1
  • 1
  • Thanks, @Mighter. This is already done. My question is about organizing the same - what should be in one function, what should in different, what to place in each class etc. – LA_ Mar 24 '11 at 05:10