Strange problems with the Spring RestTemplate in Android application-Collection of common programming errors

Nice question. Once had a similar problem. I think you targeting your app Android 4.0-4.2. Then you must perform all your operations in another thread. You perform authorization as I’ve seen from your code – it’s a short operation, so it’s better for you to use AsyncTask for this instead of util.concurrent pacakge. Here is howto for this on androidDevelopers:

http://developer.android.com/reference/android/os/AsyncTask.html

You should override doInBackground(Params…) in such a way:

class LoginTask extends AsyncTask
{
    @Override
    protected Void doInBackground(String... params) {
        HttpHeaders requestHeaders = new HttpHeaders();
        requestHeaders.setContentType(MediaType.APPLICATION_JSON); 
        HttpEntity _entity = new HttpEntity(requestHeaders);
        RestTemplate templ = new RestTemplate();
        templ.setRequestFactory(new HttpComponentsClientHttpRequestFactory());
        templ.getMessageConverters().add(new MappingJacksonHttpMessageConverter());
        ResponseEntity _response = templ.postForEntity(params[0],_entity,null) //null here in order there wasn't http converter errors because response type String and [text/html] for JSON are not compatible;
        String _body =  _response.getBody();
        return null;
    }
}

And then call it in your BeginAuthorization(View view):

new LoginTask().execute(_URL);

Hope this helps.