i want to cancel volley request if there is no response in specific time
StringRequest stringRequest = new StringRequest(Request.Method.POST, test_check_url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jsonObject = new JSONObject(response);
JSONArray jsonArray = jsonObject.getJSONArray("resultarray");
JSONObject jsonObject1 = jsonArray.getJSONObject(0);
Calendar calendar = Calendar.getInstance();
} catch (Exception e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
error.printStackTrace();
}
}){
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String,String> map = new HashMap<>();
map.put("test_id","");
map.put("chap_id","");]
map.put("type","check_test");
return map;
}
};
stringRequest.setTag(TAG);
MySingleton.getInstance(getContext()).addToRequestQueue(stringRequest);
i tried doing this:
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
if (MySingleton.getInstance(getContext()).getRequestQueue() != null) {
MySingleton.getInstance(getContext()).getRequestQueue().cancelAll(TAG);
Toast.makeText(getContext(), "Request failed"+TAG, Toast.LENGTH_SHORT).show();
}
}
}, 10000);
i want to show a toast and cancel my request if there no response in 10 seconds how can i do this? Thank you in advance