I know this must be simple, but I'm confused. I'm using AsyncHttpClient in my project. I want to create a new class, say AsyncHttpClient2
which will extend AsyncHttpClient
. This class is currently adding a token to every request. I want that if the response is UNAUTHORIZED
, it should perform some action.
This is the POST
syntax:
String url = "https://ajax.googleapis.com/ajax/services/search/images";
AsyncHttpClient client = new AsyncHttpClient();
RequestParams params = new RequestParams();
params.put("q", "android");
params.put("rsz", "8");
client.post(url, params, new JsonHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
// handler code
}
@Override
public void onFailure(int statusCode, Header[] headers, String res, Throwable t) {
// error code
}
});
This is my code:
public class TokenAsyncHttpClient extends AsyncHttpClient {
public TokenAsyncHttpClient() {
super();
this.addHeader("x-access-token", "00000000000000000000000");
}
// THIS GIVES ERROR Method does not override method from its superclass
@Override
public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
// PERFORM SOME ACTION HERE
}
}
But this gives me the following error on the @Override
line:
Method does not override method from its superclass
What am I doing wrong ? and how can I add a default action in onSuccess ?