我不明白为什么两个方法同时被调用,即AsyncHttpClient的onSuccess和onFailure方法。以下是代码段。
AsyncHttpClient client = new AsyncHttpClient();
client.post(context, url, entity, "application/json", new JsonHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, JSONObject obj)
{
System.out.print("Inside success method....");
try
{
System.out.println("Inside try of success method");
if ("SUCCESS".equals(obj.getString("status")))
{
System.out.println("Status : " + obj.getString("status"));
statusFlag = statusFlag+1;
System.out.println("Double Status Flag: "+statusFlag);
}
else
{
//statusFlag = 2;
}
}
catch (JSONException e)
{
//statusFlag = 3;
}
}
@Override
public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse)
{
if (statusCode == 404)
{
//statusFlag = 4;
}
else if (statusCode == 500)
{
//statusFlag = 5;
}
else
{
//statusFlag = 6;
}
}
});