Tom Tom - 20 days ago 5
JSON Question

Responce wait handling Android

This is my code to send json array to server and handle the responce...

b2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {



JsonArrayRequest request = new JsonArrayRequest(Request.Method.POST,
server_url, getResults(),
new Response.Listener<JSONArray>() {

@Override
public void onResponse(JSONArray response) {
// handle the response





Log.d("JsonArray",response.toString());




for(int i = 0; i < response.length(); i++) {

try {
JSONObject store = response.getJSONObject(i);
mydb.updateweb(store.getInt("_id"),store.getString("webid"),store.getString("regid"));

if(i==response.length()-1)
{
Toast.makeText( MainActivity.this, "Synced Successfully", Toast.LENGTH_SHORT).show();

mydb.updatesync();
}

} catch (JSONException e) {
e.printStackTrace();
}

}

try {
JSONObject stor = response.getJSONObject(0);
Toast.makeText( MainActivity.this, stor.getString("result"),
Toast.LENGTH_SHORT).show();

mydb.updatesync();

} catch (JSONException e) {
e.printStackTrace();
}


}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// an error occurred




Toast.makeText( MainActivity.this, "error",
Toast.LENGTH_SHORT).show();




}
}) {

@Override
public String getBodyContentType() {
return "application/json";
}
};

requestQueue.add(request);




}

});


When i send a huge amount of data its not getting response. It toast the error message. How can i handle the response. How can i resolve this issue.?

Answer

Use this...

request.setRetryPolicy(new RetryPolicy() {
                @Override
                public int getCurrentTimeout() {
                    return 100000;
                }

                @Override
                public int getCurrentRetryCount() {
                    return 100000;
                }

                @Override
                public void retry(VolleyError error) throws VolleyError {

                }
            });