0

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?

4

2 回答 2

1

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.

于 2013-08-10T01:40:02.223 回答
1

尽管一些开发人员和设计人员在内容是否应该自动刷新之间争论不休,但我认为像流这样的内容不应该自动刷新,除非您期望传入的数据非常少。

我在我的一个测试应用程序中使用 twitter4j 流式传输推文并自动刷新,twitter4j 有一个监听器,可以让您知道何时收到新的推文。首先,我在收到新的提要后立即将数据推送到 ListView 中,这有点华而不实,但很有效。然后我将数据排队,直到它达到一定的阈值并将数据推送到 ListView 中,它有点好。我认为它已经足够好了,但是当我监控我的“数据使用”时,我很清楚为什么我不应该自动刷新。

现在这里有一些示例实现:

  • (建议)进行某种类型的轮询,或者我建议您实施推送(如 GCM)以让您的客户端知道服务器中有新内容。
  • (选项)将 SyncAdapter 与服务器触发的同步一起使用
  • (推荐)让用户控制,使用像 Facebook 这样的 Pull-to-Refresh 模式或像 Google+ 这样的 ActionBar 同步按钮是非常好的。它不会让 UserExperience 变得糟糕。

现在这是您的示例请求 API 的样子,或者您可以匹配您自己的配置:

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

...
}
于 2013-08-10T03:19:50.677 回答