Created
July 1, 2014 19:15
-
-
Save marteinn/840f7ef91172261a6c0d to your computer and use it in GitHub Desktop.
Android Volley Samples: Catching a timeout error.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.android.volley.TimeoutError; | |
import com.android.volley.VolleyError; | |
import com.android.volley.Request; | |
import com.android.volley.Response; | |
import com.android.volley.toolbox.JsonObjectRequest; | |
import org.json.JSONObject; | |
Response.Listener<JSONObject> successListener = new Response.Listener<JSONObject>() { | |
@Override | |
public void onResponse(JSONObject jsonObject) { | |
// Pass | |
} | |
}; | |
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(); | |
} | |
} | |
} | |
}); | |
Request<JSONObject> request = new JsonObjectRequest(Request.Method.GET, myUrl, | |
successListener, errorListener); | |
mQueue.add(request); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you so much!