O'Reilly logo

Android Cookbook by Ian F. Darwin

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

Chapter 13. Networked Applications

13.1. Introduction: Networking

Ian Darwin

Discussion

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

Ian

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