SpringSource has released Spring for Android 1.0. Spring for Android is an extension of the Spring Framework that helps simplify the development of native Android applications. This release features a REST client (RestTemplate) and OAuth support (Spring Social).
The first feature of Spring for Android 1.0 is the REST client. You can now use the Spring RestTemplate abstraction to consume RESTful services within your native Android application. Based on Google's recommendations, RestTemplate uses the J2SE HTTP client libraries for Android 2.3+, and HttpClient for Android 2.2 and below. It supports different HTTP Message Converters, and uses Jackson or Gson for JSON marshalling, Simple XML Serializer for XML marshalling, and Android ROME for RSS/Atom marshalling. RestTemplate also supports gzip compression. Here's a basic example of RestTemplate taken from the Spring for Android reference manual, which queries Google for the search term "SpringSource".
String url = "https://ajax.googleapis.com/ajax/services/search/web?v=1.0&q={query}"; RestTemplate restTemplate = new RestTemplate(); restTemplate.getMessageConverters().add(new StringHttpMessageConverter()); String result = restTemplate.getForObject(url, String.class, "SpringSource");
The other major feature of Spring for Android 1.0 is Spring Social support. You now have the ability to use Spring Social in your Android applications, which includes an OAuth client and implementations of popular social websites like Twitter and Facebook. This release provides OAuth 1.x and 2.0 support, and includes a SQLite repository, and Android compatible Spring Security encryption.
Developers familiar with the Spring Framework will naturally expect Dependency Injection to be part of Spring for Android. However, due to the way Android drives the application lifecycle using Intents, the way Dependency Injection can be implemented is limited. Please read Clean Code in Android Applications for more information on Dependency Injection options in Android.
For more information, please read the Spring for Android Reference Manual. Spring for Android examples are available at GitHub. To get started, you can download the release distribution, or add the Maven dependencies.
<dependency> <groupId>org.springframework.android</groupId> <artifactId>spring-android-rest-template</artifactId> <version>1.0.0.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.android</groupId> <artifactId>spring-android-auth</artifactId> <version>${spring-android-version}</version> </dependency>
Be sure to read Maven Dependency Management to utilize Maven's dependency management capabilities within an Android application.