-Work in progress-
See: Reactive approach
This is a library that allows you to cache and retry failed HTTP requests. You can interact through this interface:
public interface RequestCache {
void setRequestIntervalTime(long intervalTimeInMillis);
void enqueueRequest(RequestModel requestModel);
void enqueueRequests(List<RequestModel> requestModels);
boolean sendPendingRequests();
void cancel();
void clearRequestsCache();
}
Make sure to provide your requests this way:
new RequestModel.Builder<String>()
.methodType(MethodType.POST)
.headers(new HashMap<String, String>())
.baseUrl("https://api.github.com/")
.endpoint("users/GigigoGreenLabs/repos")
.query(new HashMap<String, String>())
.body("This is the body")
.build();
- Define a Retry Policy: Manual or Automatic.
- If automatic, it'd be a good idea to register a Broadcast Receiver subscribed to the following intent-filter android.net.conn.CONNECTIVITY_CHANGE
- Maybe use AlarmManager to schedule retries.
Alternative implementation of RequestQueue using SQLite (or even a plain old file) instead of SharedPreferences. DoneAlternative implementation using RxJava to avoid callback hell. Done.Add a cancel method. Done