O'Reilly logo

Learning Android by Marko Gargenta

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Pulling Data from Twitter

We now have a framework and are ready to make the actual connection to the online Twitter-like service, pull the status data, and display that data in our application. Twitter and Twitter-like services offer many different APIs to retrieve our friends’ updates. The jtwitter.jar library exposes most of them to us via the Twitter class. Perhaps one of the most appropriate methods is getFriendsTimeline(), which returns the 20 most recent posts made over the past 24 hours from the user and her friends.

To use this Twitter API feature, we need to connect to the online service. And to do that, we need the username, password, and root API for our online service. As you recall from the previous chapter, we have already refactored most of this functionality into the YambaApplication object (see The Yamba Application Object). We can reuse all those features here because our service is part of the same application and as such has access to the same Application object.

However, we do need to make a minor update to YambaApplication, because we would also like to know whether our service is running. To do that, we’ll add a flag to YambaApplication and provide setter and getter methods to access and update that flag:

public class YambaApplication extends Application
  implements OnSharedPreferenceChangeListener {
  private boolean serviceRunning; // 1 ... public boolean isServiceRunning() ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required