Ben Groot
Ben Groot

Reputation: 5050

How to queue API calls when you're offline while using Retrofit

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.

Upvotes: 10

Views: 7126

Answers (2)

Marcin Orlowski
Marcin Orlowski

Reputation: 75629

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)

Upvotes: 13

Stas Parshin
Stas Parshin

Reputation: 8283

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?

Upvotes: 1

Related Questions