So, what is Spring for Android?

Exclusive offer: get 50% off this eBook here
Instant Spring for Android Starter [Instant]

Instant Spring for Android Starter [Instant] — Save 50%

Leverage Spring for Android to create RESTful and OAuth Android apps with this book and ebook.

$14.99    $7.50
by Anthony Dahanne | February 2013 | Open Source

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.)

RestTemplate

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.

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.

Summary

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:


Instant Spring for Android Starter [Instant] Leverage Spring for Android to create RESTful and OAuth Android apps with this book and ebook.
Published: January 2013
eBook Price: $14.99
See more
Select your format and quantity:

About the Author :


Anthony Dahanne

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.

Books From Packt


Android Database Programming
Android Database Programming

 Android User Interface Development: Beginner's Guide
Android User Interface Development: Beginner's Guide

 Android Application Testing Guide
Android Application Testing Guide

Android 3.0 Animations: Beginner’s Guide
Android 3.0 Animations: Beginner’s Guide

 Android 4: New Features for Application Development
Android 4: New Features for Application Development

 AndEngine for Android Game Development Cookbook
AndEngine for Android Game Development Cookbook

 Instant Android Fragmentation Management How-to [Instant]
Instant Android Fragmentation Management How-to [Instant]

 Spring Web Services 2 Cookbook
Spring Web Services 2 Cookbook


Your rating: None Average: 1.5 (4 votes)

Post new comment

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
v
N
C
d
d
w
Enter the code without spaces and pay attention to upper/lower case.
Code Download and Errata
Packt Anytime, Anywhere
Register Books
Print Upgrades
eBook Downloads
Video Support
Contact Us
Awards Voting Nominations Previous Winners
Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
Resources
Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software