HttpClient httpClient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(urlString);
HttpResponse response = null;
MultipartEntity mpEntity = new MultipartEntity();
StringBody sb;
String result = null;
try {
sb = new StringBody(json.toString());
mpEntity.addPart("json", sb);
httppost.setEntity(mpEntity);
response = httpClient.execute(httppost);
HttpEntity entity = response.getEntity();
if (entity != null) {
InputStream instream = entity.getContent();
result = RestClient.convertStreamToString(instream);
Log.i("Read from Server", result);
}
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(result == "true"){
this.stopSelf();
} else {
}
I get an RuntimeException in my Background Service on:
response = httpClient.execute(httppost);
I don't know why :( I do the same not in a Service and everything's ok, but in Service it throws the exception.