Before you start
This tutorial introduces XML handling on the Android platform. To build the sample application in this tutorial, the Android SDK must be installed and functional on the development computer. Building Android applications in Eclipse is recommended, but not a requirement for this tutorial. Mobile development experience is helpful, but Java™ programming skills are required for the Android applications and will be helpful for this tutorial.
Why do you care about an RSS reader for Android? And where does XML fit into the picture? First, Android is a platform that is rapidly gaining mindshare in the mobile marketplace. Even before consumer devices equipped with Android are available, thousands of developers are jumping into this mobile market, hoping to be prepared for the much anticipated introduction of Android-equipped devices in the near future. Rich devices, such as Android, demand content. Sometimes that content is in the form of games or a productivity application. Beyond mobile e-mail, however, the content that drives data usage the most is news and information. This content might look like news stories relevant to a particular financial market or something as ubiquitous as the weather forecast. And who isn't interested in the weather forecast for the upcoming weekend trip to the beach? Getting data to a mobile device in a fashion that is organic and usable becomes the challenge.
Android includes the WebKit.org browser engine, which means that it delivers a top quality browser experience to the mobile user. However, chasing down multiple Web sites for news and information can be tedious in a small screen with limited input devices. Don't misunderstand, the market has come a very long way since the WAP browser and limited text-based information, however the power of mobile information is when it is available at-a-glance: Enter RSS feeds. RSS is an acronym for "Really Simple Syndication." In essence, RSS is a convenient way to distribute information of interest. RSS makes XML data available; the data contains brief abstracts or teasers of the full information source. If interested, the user can dig deeper and get "the rest of the story" as the radio host Paul Harvey might say. This tutorial demonstrates the major aspects of XML data handling in the construction of an Android RSS reader.
This tutorial is organized into the following sections:
- RSS basics
- Android RSS reader application architecture
- Fetching and parsing XML data with SAX
- Rendering RSS data in Android
This tutorial requires several technologies that work together. You will need to obtain all of them to perform the steps of this tutorial.
- Download Eclipse from http://www.eclipse.org/downloads.
- To install the Android Developer Tools (the Eclipse Plugin), follow the instructions at http://code.google.com/android/intro/installing.htm#installingplugin
- Find the Android SDK at http://code.google.com/android. The Android SDK is a moving target. When I wrote this tutorial, the current version of the SDK was m5-rc14.
- Choose an RSS feed. This tutorial uses a feed of the most popular tutorials from the developerWorks Web site.
- Have an active Internet Connection to run the sample application.
Full source code is available from Downloads. Source code snippets in this tutorial include:
- AndroidManifest.xml snippet: This file is the application deployment descriptor for Android applications.
-
RSSReader: This class implements the main GUI and includes code for menu handling. -
RSSFeed: This class contains a parsed RSS Feed, including information about the RSS channel and a List of the includedRSSItems. -
RSSHandler: This class implements the SAX parser handler to enable the parsing of an XML stream (an RSS feed from the Internet) and populates an instance of theRSSFeed. -
RSSItem: This class represents a single RSS item parsed out of an XML stream. -
ShowDescription: This is an Activity that displays the abstract of a selectedRSSItemand includes linkable text to enable seamless launching of the Android browser to access the link available in theRSSItem. Launching this Activity demonstrates the use of an Intent with an extra Bundle in a pseudo-synchronous call. - R.java: This file represents the GUI identifiers used in the application.
Building an Android RSS/XML application requires knowledge of XML, RSS and HTTP, as well as aspects of the Android platform. An understanding of the terms below is helpful for you to get the most out of this tutorial. For additional links for more information on each of these topics, see Resources.
- Android: The flagship product of the Open Handset Alliance. This is an open source operating environment targeted for mobile devices such as cell phones.
- RSS: Really Simple Syndication is a data format used to publish information in an efficient manner.
- XML: eXtensible Mark-up Language is a self describing data format.
- HTTP: Hyper Text Transport Protocol almost exclusively transfers all RSS feeds.
- Parser: This tool is designed to extract information from one format and make it accessible to other structures. For example, an XML parser extracts data from an XML data source.
- Emulator: This software tool is representative of another system. Android is not available today on real hardware platforms to consumers; the sample application is exercised on the Android Emulator.

