Skip to content

Commit c7231d8

Browse files
committed
1 parent fa31db8 commit c7231d8

File tree

1 file changed

+34
-23
lines changed

1 file changed

+34
-23
lines changed

library/src/com/loopj/android/http/JsonHttpResponseHandler.java

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,19 @@ public void onFailure(Throwable e, JSONArray errorResponse) {
129129
//
130130

131131
@Override
132-
protected void sendSuccessMessage(int statusCode, Header[] headers, String responseBody) {
132+
protected void sendSuccessMessage(final int statusCode, final Header[] headers, final String responseBody) {
133133
if (statusCode != HttpStatus.SC_NO_CONTENT) {
134-
try {
135-
Object jsonResponse = parseResponse(responseBody);
136-
sendMessage(obtainMessage(SUCCESS_JSON_MESSAGE, new Object[]{statusCode, headers, jsonResponse}));
137-
} catch (JSONException e) {
138-
sendFailureMessage(e, responseBody);
139-
}
134+
new Thread(new Runnable() {
135+
@Override
136+
public void run() {
137+
try {
138+
Object jsonResponse = parseResponse(responseBody);
139+
sendMessage(obtainMessage(SUCCESS_JSON_MESSAGE, new Object[]{statusCode, headers, jsonResponse}));
140+
} catch (JSONException e) {
141+
sendFailureMessage(e, responseBody);
142+
}
143+
}
144+
}).start();
140145
} else {
141146
sendMessage(obtainMessage(SUCCESS_JSON_MESSAGE, new Object[]{statusCode, new JSONObject()}));
142147
}
@@ -183,24 +188,30 @@ protected Object parseResponse(String responseBody) throws JSONException {
183188
}
184189

185190
@Override
186-
protected void handleFailureMessage(Throwable e, String responseBody) {
187-
try {
188-
if (responseBody != null) {
189-
Object jsonResponse = parseResponse(responseBody);
190-
if (jsonResponse instanceof JSONObject) {
191-
onFailure(e, (JSONObject) jsonResponse);
192-
} else if (jsonResponse instanceof JSONArray) {
193-
onFailure(e, (JSONArray) jsonResponse);
194-
} else if (jsonResponse instanceof String) {
195-
onFailure(e, (String) jsonResponse);
196-
} else {
191+
protected void handleFailureMessage(final Throwable e, final String responseBody) {
192+
new Thread(new Runnable() {
193+
@Override
194+
public void run() {
195+
try {
196+
if (responseBody != null) {
197+
Object jsonResponse = parseResponse(responseBody);
198+
if (jsonResponse instanceof JSONObject) {
199+
onFailure(e, (JSONObject) jsonResponse);
200+
} else if (jsonResponse instanceof JSONArray) {
201+
onFailure(e, (JSONArray) jsonResponse);
202+
} else if (jsonResponse instanceof String) {
203+
onFailure(e, (String) jsonResponse);
204+
} else {
205+
onFailure(e, responseBody);
206+
}
207+
} else {
208+
onFailure(e, "");
209+
}
210+
} catch (JSONException ex) {
197211
onFailure(e, responseBody);
198212
}
199-
} else {
200-
onFailure(e, "");
201213
}
202-
} catch (JSONException ex) {
203-
onFailure(e, responseBody);
204-
}
214+
}).start();
215+
205216
}
206217
}

0 commit comments

Comments
 (0)