Your message has been sent.
This article has been saved to your account.
Go to my account
This article has been emailed to your Kindle.
Send this article
This article, by Anthony Dahanne author of Instant Spring for Android Starter provides a brief overview of how Spring for Android has an extension of the Spring Framework that helps to simplify the development of native Android applications.
Its current Version 1.0.0.RELEASE features a REST client, RestTemplate and OAuth, an authorization protocol (Spring Social) to help you build your apps.
In this article, we will go through the main aspects of Spring for Android: RestTemplate, Auth, and what Spring for Android is not.
(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 http://android-developers.blogspot.ca/2011/09/androids-http-clients.html. 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.
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 :
- Top 5 Must-have Android Applications [Article]
- Creating, Compiling, and Deploying Native Projects from the Android NDK [Article]
- Manifest Assurance: Security and Android Permissions for Flash [Article]
eBook Price: €7.99
Book Price: €15.99
About the Author :
Anthony Dahanne is a Java software developer since 2005. His favorite topics include Android, Continuous Integration, Web Services, and of course, core Java development.
During his spare time, he enjoys hacking on some open source Android app (G2Android, ReGalAndroid, and so on). He also contributes from time to time to build/IDE plugins usually involving Maven and Eclipse.
You can meet him at one of the many Java-related user group gatherings at Montréal (Android Montréal, Montréal JUG, Big Data Montréal, and so on).
Working at Terracotta, he's currently implementing the REST management tools for EhCache.