Created
July 1, 2014 19:15
Android Volley Samples: Catching a timeout error.
This file contains 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); |
Thank you so much!
Thank You
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you so much!