I searched everything, but did not find the answer to this question.
In my Android application, the user can use the application offline, and some events generate HTTP GET requests to my server. I use Volley, and when the user is online, the requests work fine, but in offline mode they immediately crash and are removed from the request queue.
I wanted Volley to save these requests, and try again when the server is available or at least continues trying. Is this possible?
Here is how I do it:
StringRequest request = new StringRequest(Request.Method.GET, url, listener, listener); request.setRetryPolicy(new DefaultRetryPolicy(8000, 2, 1.5f)); postToDefaultQueue(request); private void postToDefaultQueue (StringRequest request) { if (sQueue == null) { sQueue = Volley.newRequestQueue(mContext.get()); } sQueue.add(request); }
Thanks a lot, any help appreciated
Edit
Therefore, I managed to return the request to the queue after it was refused. Code below:
private class DummyListener implements Response.Listener<String>, Response.ErrorListener { String mUrl; public DummyListener (String url){ mUrl = url; } @Override public void onErrorResponse(final VolleyError error) { new Timer().schedule(new TimerTask() { @Override public void run() { Log.v(DummyListener.class.getSimpleName(), "ErrorResponse", error); offlineStringGetRequest(mUrl); } }, 5000); } @Override public void onResponse(String response) { Log.d(DummyListener.class.getSimpleName(), "Response: " + response); } }
The problem remains that if I kill the application, the queue will be destroyed and the request will never be executed.
Edit2
Noticed that some people liked this question. I ended up using Path ( https://github.com/path/android-priority-jobqueue ) with some changes for the job. It worked great. I just want Volley to have a native way of doing this.