为什么AsyncHttpClient方法同时调用onSuccess和onFailure方法

时间:2016-05-02 14:13:21

标签: android json rest android-async-http

我不明白为什么两个方法同时被调用,即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;
            }
        }
    });

0 个答案:

没有答案