com.loopj.android.http
Class AsyncHttpResponseHandler

java.lang.Object
  extended by com.loopj.android.http.AsyncHttpResponseHandler
Direct Known Subclasses:
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), 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) {
         // Response failed :(
     }

     @Override
     public void onFinish() {
         // Completed the request (either success or failure)
     }
 });
 


Constructor Summary
AsyncHttpResponseHandler()
          Creates a new AsyncHttpResponseHandler
 
Method Summary
protected  void handleFailureMessage(Throwable e)
           
protected  void handleMessage(Message msg)
           
protected  void handleSuccessMessage(String responseBody)
           
protected  Message obtainMessage(int responseMessage, Object response)
           
 void onFailure(Throwable error)
          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(String content)
          Fired when a request returns successfully, override to handle in your own code
protected  void sendFailureMessage(Throwable e)
           
protected  void sendFinishMessage()
           
protected  void sendMessage(Message msg)
           
protected  void sendStartMessage()
           
protected  void sendSuccessMessage(String responseBody)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AsyncHttpResponseHandler

public AsyncHttpResponseHandler()
Creates a new AsyncHttpResponseHandler

Method Detail

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

Parameters:
content - the body of the HTTP response from the server

onFailure

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

Parameters:
error - the underlying cause of the failure

sendSuccessMessage

protected void sendSuccessMessage(String responseBody)

sendFailureMessage

protected void sendFailureMessage(Throwable e)

sendStartMessage

protected void sendStartMessage()

sendFinishMessage

protected void sendFinishMessage()

handleSuccessMessage

protected void handleSuccessMessage(String responseBody)

handleFailureMessage

protected void handleFailureMessage(Throwable e)

handleMessage

protected void handleMessage(Message msg)

sendMessage

protected void sendMessage(Message msg)

obtainMessage

protected Message obtainMessage(int responseMessage,
                                Object response)