0

I am using intentService for making http calls with Ion. On Wifi it works well but when I switch to data network things start breaking.

Ion.with(Application.getApplicationContext())
            .load(url)
            .as(new TypeToken<Object>() {})
            .withResponse()
            .setCallback(new FutureCallback<Response<Object>>() {
                @Override
                public void onCompleted(Exception e, Response<Object> response) {
                    if(e == null) {
                        Bundle bundle = new Bundle();
                        bundle.putSerializable("result", (Serializable) response.getResult());
                        rec.send(response.getHeaders().code(), bundle);
                    }
                }
            });

Above is the code which i am using in IntentService I am getting "java.io.IOException:non 2xx status line:HTTP/1.1 500 internal server error."

  • I can't speak to the specific error you're getting but IntentServices don't play nicely when making asyc network calls. By design the IntentService will automatically finish itself when it has carried out the work inside its onHandleIntent method. It won't wait for the result of an async method to return. – Ivan Wooll Nov 06 '15 at 15:20

1 Answers1

3

Since you are using an intent service, as soon the onHandleIntent method completes, the service will terminate. Ion's request will detect the service context is terminated and cancel the request.

However, it seems you are using the main application context, rather than the service context, in which case it should work. In any case, you are getting a correct response (500 is still successful request and response). The 500 indicates the issue is server side.

koush
  • 2,972
  • 28
  • 31