Execute POST request until network connection available with Volley on Android

1.2k views Asked by At

I've been wondering if there is any way with Volley to queue and then execute a request until the mobile data connection is available.

I have to create an Android app that have to work in areas with no mobile service, so I have to queue and postpone any POST request that my app perform using Volley, until the internet mobile service is available.

The app have a registration form that have to be filled, and when I press send, if there is mobile service the form is sent, but if not, the form information have to be store and the POST request have to be queue in order to be performed later when the phone count with service connection.

Is there any way to do this with Volley? Or with any other Android HTTP Connection library.

Thanks

1

There are 1 answers

4
Tyler Kiser On BEST ANSWER

I saved my information to a database on the device with a "transmitted" flag. This way, even if the user completely closes the app, the information is always saved.

I then created a service (https://developer.android.com/training/run-background-service/create-service.html) that checks every 15 minutes for records that have not been transmitted. If they are found, it tries to transmit again.

The transmit is also executed as soon as a user enters and saves the information. Successful transmissions update the "transmitted" flag on the record.