Chapter 13. Networked Applications

13.1. Introduction: Networking

Ian Darwin


Networking. One could talk about it for hours. In the Android context it is primarily about web services, which are services accessed by another program (your Android app) over the HTTP (“web”) protocol. Web services come in two flavors: XML/SOAP and RESTful. XML/SOAP web services are more formal and thus have significantly more overhead, both at development time and at runtime, but offer more capability. RESTful services are much lighter weight, and are not tied to XML: we have recipes on using JSON (JavaScript Object Notation) and other formats with web services.

Choose your protocol wisely

While Java makes it easy to create network connections on any protocol, experience shows that HTTP (and HTTPS) are the most universal. If you use a custom protocol talking to your own server, there are some users who will not be able to access your server. Bear in mind that in some countries, high-speed data (a.k.a. 3G) is either not yet available or very expensive, whereas GPRS/EDGE is less expensive and more widely available. Most GPRS service providers only allow HTTP/HTTPS connections, often through a WAP proxy. That being said, there may be things you need to do that can’t be done via HTTP—for example, because the protocol demands a different port number (e.g., SIP over port 5000). But do try to make HTTP your first choice when you can—you’ll include more customers.

13.2. Using a RESTful Web Service


Get Android Cookbook now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.