views:

44

answers:

1

I am having a List View, all the list items(Text) need be to updated from a web service. My application can query the web service to fetch all the list items at one go or can query to fetch one list item at a time. I having following queries 1)If i query the web service to fetch all the list items at once, it takes around 15 secs to download and display it in List. User might think the app is not responding. 2) If i query the web service for each list item, when the user scroll up or down multiple queries are sent. So i am downloading items which the user might not probably see. if the list is scrolled up.

Please suggest a good design pattern for such a scenario.

A: 

What you could do is to have the following

  • A background Android service which downloads fresh items from your webservice in given time intervals
  • A sqlite database and according ContentProvider which stores/fetches the items from the DB
  • A list activity which retrieves a cursor on the items from the registered ContentProvider you wrote

Basically the background service will store the items in the local sqlite db through the ContentProvider you write. The activity will then retrieve a cursor to the items, again through the ContentProvider.

This gives you the benefits that

  • it will be fast, working with cursors and standard mechanisms
  • users will still see the items also if they temporaneously loose connectivity
  • your list will automatically refresh the items, being registered as Observer on the ContentProvider
Juri
@Juri: Consider the following use case. If i have a list of 100 items. I start downloading list item starting from top, but the user immediately scrolls to the bottom of the list. User has to wait until the query of 100th item goes to the web service.
SpunkerBaba
Personally, taking into consideration that it takes up to 15 secs to download all the items from the webservice, I would download them ALL in the background service, but not during scrolling of the list view. Shouldn't be a problem. Loading during scrolling dramatically impacts performance for sure..
Juri