So, what is Spring for Android?

Leverage Spring for Android to create RESTful and OAuth Android apps

(For more resources related to this topic, see here.)


The RestTemplate module is a port of the Java-based REST client RestTemplate, which initially appeared in 2009 in Spring for MVC. Like the other Spring template counterparts (JdbcTemplate, JmsTemplate, and so on), its aim is to bring to Java developers (and thus Android developers) a high-level abstraction of lower-level Java API; in this case, it eases the development of HTTP clients.

In its Android version, RestTemplate relies on the core Java HTTP facilities (HttpURLConnection) or the Apache HTTP Client. According to the Android device version you use to run your app, RestTemplate for Android can pick the most appropriate one for you. This is according to Android developers' recommendations.

See This blog post explains why in certain cases Apache HTTP Client is preferred over HttpURLConnection.

RestTemplate for Android also supports gzip compression and different message converters to convert your Java objects from and to JSON, XML, and so on.

Auth/Spring Social

The goal of the Spring Android Auth module is to let an Android app gain authorization to a web service provider using OAuth (Version 1 or 2).

OAuth is probably the most popular authorization protocol (and it is worth mentioning that, it is an open standard) and is currently used by Facebook, Twitter, Google apps (and many others) to let third-party applications access users account.

Spring for Android Auth module is based on several Spring libraries because it needs to securely (with cryptography) persist (via JDBC) a token obtained via HTTP; here is a list of the needed libraries for OAuth:

  • Spring Security Crypto: To encrypt the token

  • Spring Android OAuth: This extends Spring Security Crypto adding a dedicated encryptor for Android, and SQLite based persistence provider

  • Spring Android Rest Template: To interact with the HTTP services

  • Spring Social Core: The OAuth workflow abstraction

While performing the OAuth workflow, we will also need the browser to take the user to the service provider authentication page, for example, the following is the Twitter OAuth authentication dialog:

What Spring for Android is not

SpringSource (the company behind Spring for Android) is very famous among Java developers. Their most popular product is the Spring Framework for Java which includes a dependency injection framework (also called an inversion of control framework). Spring for Android does not bring inversion of control to the Android platform.

In its very first release (1.0.0.M1), Spring for Android brought a common logging facade for Android; the authors removed it in the next version.


In this article, we have learned that Spring for Android helps in easy development of Android applications. We learned the details about the important modules present in it and its functions. We also learnt about dependency injection framework in short and that Spring for Android does not bring inversion of control to the Android platform.

Resources for Article :

Further resources on this subject:

Books to Consider

comments powered by Disqus