Android Open Source - spring-for-android-starter-book Main Activity

From Project

Back to project page spring-for-android-starter-book.


The source code is released under:

Apache License

If you think the Android project spring-for-android-starter-book listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

//from   w w w.  j  a v a 2  s.c  o m
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.web.client.RestTemplate;

import android.os.AsyncTask;
import android.os.Bundle;
import android.widget.TextView;

public class MainActivity extends Activity {

  public void onCreate(Bundle savedInstanceState) {
    final TextView resultTextView = (TextView) findViewById(;

    AsyncTask<String, Void, String> simpleGetTask =  new AsyncTask<String, Void, String>() {
      protected String doInBackground(String... params) {
        // executed by a background thread

        // create a new RestTemplate instance
        RestTemplate restTemplate = new RestTemplate();
        // add the String message converter, since the result of the call will be a String
        restTemplate.getMessageConverters().add(new StringHttpMessageConverter());
        // Make the HTTP GET request on the url (params[0]), marshaling the response to a String
        return restTemplate.getForObject(params[0], String.class);
      protected void onPostExecute(String result) {
        // executed by the UI thread once the background thread is done getting the result
    String url = "";
    // triggers the task; it will update the resultTextView once it is done

Java Source Code List