0

Inside my app I know that the connection is lost in this moment. What is the best way to send a http post request until get the internet connection back? An approach is to retry the request a few times, but is there something smarter?

LuZa
  • 430
  • 1
  • 5
  • 26
  • The only thing to do is to alert the user that there s no internet and your app needs internet to function properly. Its up to the user afterwards. But if its something like a background task, like for analytics and does not matter if its sent later on as well, then keep track of the requests and use `Reachability` and when internet is back re trigger all of them. – GoodSp33d May 10 '19 at 08:33

1 Answers1

2

What you can do is save your request on a database if connection fails (you can use any database, even shared preferences). Then implement a connection listener to listen if connection goes back. If connection goes back, get the request on the database and retry it again, if it succeeds delete that request on the database.

Saving the request is up to you on how you would want to group your request. For example, login request, you can save it on your table LOGIN_QUERY_TABLE with column username and password, if connection goes back, get the username and password to retry logging in again.

Tenten Ponce
  • 2,256
  • 1
  • 9
  • 27