Twitter Integration for Android App

I want a simple example of implementing Twitter in our application. I would prefer it not be visible; It should only open in our application area. After logging in, the user can post tweets to his account.

+4
source share
1 answer

A good question that leaves a lot of room for counter questions :-)

I see at least two paths following the path (note that I know very little about twitter or how it is used):

  • You sync twitter data (β€œtweets”?!?) On your phone for later viewing.

  • You always view a snapshot of the current tweets on this channel and do not store anything (except for user credentials).

Starting with the first alternative , you usually want to synchronize the SQLite database (possibly with the help of a content provider ) on the target with the data from the twitter channel on Twitter web servers (you can learn a little about what the regular twitter API looks like here )

This synchronization will be performed using the service background on the phone. Your actual GUI will not contact this service, it will rather read data from (and only from) the local SQLite database. Thus, your graphical interface will not depend on latency of the network, data traffic or the availability of data from the Internet. It will depend only on connecting to the database for your local target. Make sure you start the service in a separate thread. By default, it will run in the main thread (also called "GUI-thread").

You can transfer an entry to AlarmManager , which will wake up your background service from time to time; the service will cache twitter data in the database, and then kill itself (to save resources).

The second alternative does not require a database caching level (however, it is recommended to get rid of web dependencies in your GUI, then the database will contain only the latest data, old data will be overwritten regardless of whether the user has read it or not).

In both alternatives, you probably want to keep some basic user information, such as username and password. You can save these values ​​in the SQLite database or, if you want, simply: in the infrastructure General settings ./p>

You will most likely also need to read and parse XML data from the Internet. This reading and parsing will be performed using the service level (remember: run it in a separate thread to keep up with the user interface or even get the application timeout without an answer).

+6
source

Source: https://habr.com/ru/post/1340270/


All Articles