guo guo - 5 days ago 5
Android Question

android volley OnTimeout mehod

How to handle the timeout event in volley, e.g., give a hint for user? I cannot find any useful stuff after googling.

Should I write the logic in

Response.ErrorListener()
when creating a request?

Answer

There is an Exception called TimeoutError defined in Volley , You can make use of that. adding an example below

Response.ErrorListener errorListener = new Response.ErrorListener() {
    @Override
    public void onErrorResponse(VolleyError volleyError) {
        if (volleyError.networkResponse == null) {
            if (volleyError.getClass().equals(TimeoutError.class)) {
                // Show timeout error message
                Toast.makeText(getContext(),
                        "Oops. Timeout error!",
                        Toast.LENGTH_LONG).show();
            }
        }
    }
});

Also please see this link

Comments