I am trying to set a timeout at http post using android-async-http:1.4.7 to manage the server down but setting httpClient.setTimeout(1000) it doesn't work and onFailure callback doesn't catch an exception. here my code
AsyncHttpClient httpClient = new AsyncHttpClient();
RequestParams requestParams = new RequestParams();
String s= sharedPrefs.getString("type_nn", "VGG");
requestParams.put("network", s);
if (destination== null) {
destination = new File(path);
}
requestParams.put("file", destination);
httpClient.setTimeout(1000);
httpClient.post("http://url", requestParams, new JsonHttpResponseHandler() {
@Override
public void onFailure(int statusCode, Header[] headers, java.lang.Throwable throwable, org.json.JSONArray response) {
Toast.makeText(activity, "Error", Toast.LENGTH_SHORT).show();
progressChargePhoto.setVisibility(View.GONE);
}
@Override
public void onSuccess(int statusCode, Header[] headers, org.json.JSONArray response) {
...
}
}
Try adding this override:
There is another one you can override but i don't think you need it, but just in case:
And be careful with your on success, maybe you need to add the one with the JSONObject in the signature.