Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Chapter 15: Building and Consuming Services - Pg. 383

Chapter 15 Building and Consuming Services The Android Platform provides a complete software stack. This means you get an operating system and middleware, as well as working applications (such as a phone dialer). Alongside all of this, you have an SDK that you can use to write applications for the platform. Thus far, we've seen that we can build applications that directly interact with the user through a user interface. We have not, however, discussed background services or the possibilities of building components that run in the background. In this chapter, we are going to focus on building and consuming services in Android. First we'll discuss consuming HTTP services, and then we'll cover a nice way to do simple background tasks, and finally we'll discuss interprocess communication--that is, communication between applications on the same device. Consuming HTTP Services Android applications and mobile applications in general are small apps with a lot of functionality. One of the ways that mobile apps deliver such rich functionality on such a small device is that they pull information from various sources. For example, most Android smartphones come with the Maps application, which provides sophisticated mapping functionality. We, however, know that the application is integrated with the Google Maps API and other services, which provide most of the sophistication. That said, it is likely that the applications you write will also leverage information from other applications and APIs. A common integration strategy is to use HTTP. For example, you might have a Java servlet available on the Internet that provides services you want to leverage from one of your Android applications. How do you do that with Android? Interestingly, the Android SDK ships with a variation of Apache's HttpClient (http://hc.apache.org/httpclient-3.x/), which is universally used within the J2EE space. The Android version has been modified for Android, but the APIs are very similar to the APIs in the J2EE version. 383