Search code examples
androidretrofitrx-java

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.


Solution

  • 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)