ChuckKelly
ChuckKelly

Reputation: 1740

How to consistently and efficiently refresh a listview feed of content?

I currently have several fragment tabs , each with a feed of user statuses, being I have about a 100 other users posting from their accounts there is constantly new data every few minutes. currently the users only choice is to switch fragments back and fourth to get the entire fragment to reload which sends another http request and returns the new data as well as all the old data the user already had. it just doesnt seem efficient, know there has to be a better way. Can someone give me a overview of the most efficient way to keep this data fresh without having the user switch tabs back and fourth?

Is this where using sqlite and/or services comes into play?

Upvotes: 0

Views: 299

Answers (2)

Milan
Milan

Reputation: 1875

Though some developers and designers argue between if content should be refreshed automatically of not, I argue content like streams shouldn't be refreshed automatically unless you are expecting very less incoming data.

I have used twitter4j to stream tweets and refresh automatically in one of my test app, twitter4j has a listener that lets you know when new tweets are received. First I pushed data into ListView as soon as new feeds were received and it was kind of flashy but, efficient. Then I queued up data until it reached certain threshold and pushed data into ListView, it was bit better. I thought it was good enough but, when I monitored my "Data Usage", i quite realized why I shouldn't refresh automatically.

Now here are some example implementation:

  • (Suggest) Do some type of polling or I recommend you to implement push(like GCM) to let your client-side know that there's new content in the server.
  • (Option) Use SyncAdapter with server triggered sync
  • (Recommend) Let user be in control, it's more than okay to use Pull-to-Refresh pattern like Facebook or ActionBar sync button like Google+. It will not make UserExperience any bad.

Now here's how your sample request API should be like or you can match your own config:

{
"fromIndex": 0,
"toIndex": 10

...
}

Upvotes: 1

jac1013
jac1013

Reputation: 408

well, i'll try to give you a general overview to see if you can get it without the need of getting into deepest details, an idea it just came to my mind:

1- you need to configure your server to retrieve from an "specific" point of the content or retrieve a token that you will pass to the server (on next HttpRequest) to know from where part of the content or from where "index" start to send the content again.

2- you need to have a Listener (i dont know how you are showing your data but this is the case of a ListView) that tells you when the user is closely to get to the end of the ListView and let't say if there are already 10 elements, in element 7 the Listener should call the method to get more content from the server.

3- Yes, you need to keep the data already retrieve in SQLite temporarily, you can't use SharedPreference to keep it because it probably would be a lot of data and maintain it in memory could be a bad idea, writing a file is not an option here neither, so SQLite is your best friend in this case.

Maybe there would be more problems specifics about what you are trying to achieve but to me in a general perspective, those 3 points should at least help you in the direction to go.

Upvotes: 1

Related Questions