com.baidu.sapi2.http
类 AsyncHttpResponseHandler

java.lang.Object
  继承者 com.baidu.sapi2.http.AsyncHttpResponseHandler
直接已知子类:
BinaryHttpResponseHandler, JsonHttpResponseHandler

public class AsyncHttpResponseHandler
extends Object

Used to intercept and handle the responses from requests made using AsyncHttpClient. The onSuccess(String) method is designed to be anonymously overridden with your own response handling code.

Additionally, you can override the onFailure(Throwable, String), onStart(), and onFinish() methods as required.

For example:

 AsyncHttpClient client = new AsyncHttpClient();
 client.get("http://www.google.com", new AsyncHttpResponseHandler() {
     @Override
     public void onStart() {
         // Initiated the request
     }
 
     @Override
     public void onSuccess(String response) {
         // Successfully got a response
     }
 
     @Override
     public void onFailure(Throwable e, String response) {
         // Response failed :(
     }
 
     @Override
     public void onFinish() {
         // Completed the request (either success or failure)
     }
 });
 


字段摘要
protected static int FAILURE_MESSAGE
           
protected static int FINISH_MESSAGE
           
protected static int START_MESSAGE
           
protected static int SUCCESS_MESSAGE
           
 
构造方法摘要
AsyncHttpResponseHandler()
          Creates a new AsyncHttpResponseHandler
 
方法摘要
protected  void handleFailureMessage(Throwable e, String responseBody)
           
protected  void handleMessage(android.os.Message msg)
           
protected  void handleSuccessMessage(int statusCode, String responseBody)
           
protected  android.os.Message obtainMessage(int responseMessage, Object response)
           
 void onFailure(Throwable error)
          已过时。 use onFailure(Throwable, String)
 void onFailure(Throwable error, String content)
          Fired when a request fails to complete, override to handle in your own code
 void onFinish()
          Fired in all cases when the request is finished, after both success and failure, override to handle in your own code
 void onStart()
          Fired when the request is started, override to handle in your own code
 void onSuccess(int statusCode, String content)
          Fired when a request returns successfully, override to handle in your own code
 void onSuccess(String content)
          Fired when a request returns successfully, override to handle in your own code
protected  void sendFailureMessage(Throwable e, byte[] responseBody)
           
protected  void sendFailureMessage(Throwable e, String responseBody)
           
protected  void sendFinishMessage()
           
protected  void sendMessage(android.os.Message msg)
           
protected  void sendStartMessage()
           
protected  void sendSuccessMessage(int statusCode, String responseBody)
           
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

字段详细信息

SUCCESS_MESSAGE

protected static final int SUCCESS_MESSAGE
另请参见:
常量字段值

FAILURE_MESSAGE

protected static final int FAILURE_MESSAGE
另请参见:
常量字段值

START_MESSAGE

protected static final int START_MESSAGE
另请参见:
常量字段值

FINISH_MESSAGE

protected static final int FINISH_MESSAGE
另请参见:
常量字段值
构造方法详细信息

AsyncHttpResponseHandler

public AsyncHttpResponseHandler()
Creates a new AsyncHttpResponseHandler

方法详细信息

onStart

public void onStart()
Fired when the request is started, override to handle in your own code


onFinish

public void onFinish()
Fired in all cases when the request is finished, after both success and failure, override to handle in your own code


onSuccess

public void onSuccess(String content)
Fired when a request returns successfully, override to handle in your own code

参数:
content - the body of the HTTP response from the server

onSuccess

public void onSuccess(int statusCode,
                      String content)
Fired when a request returns successfully, override to handle in your own code

参数:
statusCode - the status code of the response
content - the body of the HTTP response from the server

onFailure

public void onFailure(Throwable error)
已过时。 use onFailure(Throwable, String)

Fired when a request fails to complete, override to handle in your own code

参数:
error - the underlying cause of the failure

onFailure

public void onFailure(Throwable error,
                      String content)
Fired when a request fails to complete, override to handle in your own code

参数:
error - the underlying cause of the failure
content - the response body, if any

sendSuccessMessage

protected void sendSuccessMessage(int statusCode,
                                  String responseBody)

sendFailureMessage

protected void sendFailureMessage(Throwable e,
                                  String responseBody)

sendFailureMessage

protected void sendFailureMessage(Throwable e,
                                  byte[] responseBody)

sendStartMessage

protected void sendStartMessage()

sendFinishMessage

protected void sendFinishMessage()

handleSuccessMessage

protected void handleSuccessMessage(int statusCode,
                                    String responseBody)

handleFailureMessage

protected void handleFailureMessage(Throwable e,
                                    String responseBody)

handleMessage

protected void handleMessage(android.os.Message msg)

sendMessage

protected void sendMessage(android.os.Message msg)

obtainMessage

protected android.os.Message obtainMessage(int responseMessage,
                                           Object response)


Copyright © 2013. All Rights Reserved.