I'm using Retrofit in combination with rx-java and have the following question:
Is there a way to queue API calls to a server when the device is offline so that they can be fired when the device is back online again.
Retrofit is type-safe REST client for Android and Java which aims to make it easier to consume RESTful web services.
enqueue(Callback<T> callback) Asynchronously send the request and notify callback of its response or if an error occurred talking to the server, creating the request, or processing the response. Response<T> execute() Synchronously send the request and return its response.
Retrofit is a REST Client for Java and Android allowing to retrieve and upload JSON (or other structured data) via a REST based You can configure which converters are used for the data serialization, example GSON for JSON.
EDIT: March 2021 you should now use Work Manager instead.
You need to add queue to your project in the first place and pipe Retrofit jobs thru that queue. So either create own queue or check if libraries like android-priority-jobqueue fit your requirements (that one also handles persistency of queued jobs, so app kill/reboot is less painful)
I think Marcin Orlowski's answer was good. But if you want to go with rxjava, you can use .retry()
with check, are you online, inside of it.
rxjava: Can I use retry() but with delay?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With