在Android应用程序集成的Twitter

问题描述:

我希望在我们的应用程序中实现微博的一个简单的例子。我想preFER,这不是可浏览;它应该只在我们的应用领域打开。登录之后,用户可以张贴在他/她的帐户的鸣叫。

I want a simple example of implementing Twitter in our application. I would prefer that it not be browsable; it should open on our application area only. After login the user can post tweets on his/her account.

好问题留下很大的空间反的问题: - )

Good question that leaves very much room for counter-questions :-)

我看到至少有两种方法可以走的路径(注意,我不知道很多有关Twitter或如何使用它):

I see at least two ways to walk down the path (note that I don't know much about twitter or how it's used):

  1. 您同步Twitter的数据(推特?!?)在手机上以供日后观赏。

  1. You synchronize twitter data ("tweets"?!?) on the phone for later viewing.

您随时查看在给定通道的当前鸣叫的快照,并没有存储任何(除了用户凭证)。

You always view a snapshot of the current tweets on a given channel and don't store anything (except for user credentials).

作为第一选择的你通常希望或许还有一个自定义的content提供商)(你可以阅读了一下什么公共Twitter的API看起来像的

As of the first alternative you'd typically want to synchronize a SQLite database (perhaps with a custom content provider) on the target with data from a twitter channel on the twitter web servers (you can read up a bit on what the public twitter API looks like here).

此同步将在手机上的背景服务来完成。您的实际图形用户界面不会与该服务本身进行通信,它宁愿读(只有从)本地SQLite数据库的数据。这样,你的GUI将不依赖于网络延迟,数据流量或数据可用性的网络。这将仅仅依赖于数据库连接在本地的目标。确保你在一个单独的线程中运行的服务。默认情况下,将在主线程中运行(也称为GUI线程)。

This synchronization would be done by a background service on the phone. Your actual GUI would not communicate with this service itself, it would rather read data from (and only from) the local SQLite database. This way your GUI wouldn't depend on network latency, data traffic or data availability from the web. It would only depend on database connectivity on your local target. Make sure you run your service in a separate thread. By default it will run in the main thread (aka the "GUI-thread").

您可以传递一个条目的AlarmManager每一个现在,然后将唤醒你的后台服务;该服务将Twitter的缓存数据库中的数据,然后杀死自己(节约资源)。

You could pass an entry to the AlarmManager that would wake up your background service every now and then; the service would cache twitter data in the database and then kill itself (to save resources).

第二个选择就没有必要要求数据库缓存层(不过建议你的GUI层摆脱网络依赖,该数据库将随后只包含最新的数据,旧数据会不管被覆盖,如果用户已经阅读与否)。

The second alternative wouldn't necessary require the database caching layer (however recommended to get rid of the web dependencies in your GUI layer, the database would then only contain the latest data, old data would be overwritten regardless if the user have read it or not).

在这两种备选方案你可能要存储一些基本的用户信息,如用户名和密码。你可以在SQLite数据库中存储这些值,或者,如果你想保持简单:在的共享preferences 的基础设施。

In both alternatives you'd probably want to store some basic user info, like user name and password. You could store these values in a SQLite database or if you want to keep it simple: in the Shared Preferences infrastructure.

您很可能还需要阅读和网络分析XML 数据。这个阅读和解析将由服务层来完成(记住:在单独的线程中运行,以避免滞后UI或甚至得到一个应用无响应超时)。

You would most likely also need to read and parse XML data from the web. This reading and parsing would be done by the service layer (remember: run it in a separate thread to avoid lagging the UI or even getting a Application Not Responding time-out).