App freezing inside Ion's completion callback

438 views Asked by At

I'm using Ion to handle my request, then I process the response using its onCompleted callback.

My problem is that the app completely freezes before it finishes doing what it's supposed to inside this callback. No crashes, no errors, nothing. It just freezes.

When debugging, it never runs the next line of code after it freezes. I tried removing all code inside my handleResponse method, but it still freezes at another point.

Here are the relevant parts of my code (not the exact code though):

private void performSync() {
    Ion.with(mContext.get())
       .load(API_URL)
       .setHeader("Content-Type", "application/json")
       .setStringBody(json)
       .asString()
       .setCallback(new FutureCallback<String>() {
           @Override
           public void onCompleted(Exception e, String result) {
                 // Some code to map response.
                 ...

                 // Freezes inside this method.
                 handleResponse(myResponse);

                 // Freezes here if I remove the above code.
                 myService.sendBroadcast(MY_ACTION);
           }
       });
}

private void handleResponse(Object myResponse) {
    // Do something with my response (extract a list from it).
    ...

    // Process data.
    for (Object object : listFromResponse) {
       // Do stuff with the objects. Works fine until the very last object.
    }

    // Freezes before this line. It never gets here.
    PreferenceUtils.saveStringPreference(MY_PREFERENCE, someValue);
}

I'm sorry for the inaccurate code, I can't post the real thing. But the actual code follows the same structure above and it should give you guys an idea.

I'm having a hard time figuring out this issue. It looks like a threading problem, but since Ion works asynchronously it shouldn't be freezing the app.

1

There are 1 answers

1
koush On BEST ANSWER

The app is freezing in your code (the callback), not Ion. I don't know what you're doing, but step through and into methods in a debugger and find out what exactly is hanging.

Try commenting code until it stops freezing. That's probably the easiest way to find the offending line.