Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your profile (name, country/region, and company) is displayed to the public and will accompany any content you post. You may update your IBM account at any time.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

Build a mobile RSS reader

Handle XML with Android

Frank Ableson is an entrepreneur and software developer in northern New Jersey, specializing in mobile and embedded application software. He is currently authoring a book about Android application development for Manning Publications. His professional interests are embedded systems, wireless communications, and automotive electronics. His biggest fans are his wife, Nikki, and their children.

Summary:  What good is a mobile computing environment if you can't keep track of your favorite news feeds on the go? Sure, you can use Android's browser to read your favorite Web sites, but it's unlikely the sites are optimized for a screen two inches high. And besides, then you'll miss the opportunity to integrate RSS or other XML data with other mobile applications to make your own mash-ups. This tutorial shows you how to use the Android Developer Tools to read, parse, and display XML data.

Date:  18 Mar 2008
Level:  Intermediate PDF:  A4 and Letter (328 KB | 33 pages)Get Adobe® Reader®

Activity:  175778 views
Comments:  

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.

About this tutorial

Frequently used acronyms

  • DOM: Document Object Model
  • GUI: Graphical user interface
  • HTTP: Hyper Text Transport Protocol
  • RSS: Really Simple Syndication
  • SAX: Simple API for XML
  • SDK: Software Development Kit
  • XML: Extensible Markup Language

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

Prerequisites

This tutorial requires several technologies that work together. You will need to obtain all of them to perform the steps of this tutorial.

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 included RSSItems.
  • 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 the RSSFeed.
  • 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 selected RSSItem and includes linkable text to enable seamless launching of the Android browser to access the link available in the RSSItem. 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.

Terminology

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.

1 of 9 | Next

Comments



static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=XML, Open source
ArticleID=295231
TutorialTitle=Build a mobile RSS reader
publish-date=03182008
author1-email=fableson@msiservices.com
author1-email-cc=dwxed@us.ibm.com