I'm working on a project using Retrofit
to make calls in an API, however I need to make one of the calls refreshable depending on the timeout returned by the API while displaying an AlertDialog
on the screen. What are the ways forward on this topic?
Asked
Active
Viewed 295 times
1

rodrigomedeiros
- 61
- 7
-
You may use [Observable](https://developer.android.com/reference/java/util/Observable.html) class – Harmantj Jun 19 '17 at 13:01
1 Answers
0
I hope this would help as alternative solution
I had similar problem once. I ended up with requesting the API from AlertDialog
and
upon successful response displayed it on AlertDialog
else
displayed the Retry Button
that would resend the request (when request timeout or similar issues)

Ait Bri
- 498
- 6
- 15
-
Retry `Button` is not solution for me. The Retry must be automatic. – rodrigomedeiros Jun 19 '17 at 13:30
-
https://stackoverflow.com/questions/29921667/retrofit-and-okhttpclient-catch-connection-timeout-in-failure-method – Ait Bri Jun 19 '17 at 13:47
-
Not yet. It is not connection timeout, the API responds fast with code 200. I who need a while to redo the call. – rodrigomedeiros Jun 19 '17 at 13:52
-
-
Ok @Amit Bhandari, i'm sorry. I call an API which should return me a PDF, however, it might happen that it's still being prepared. In that case, it returns me a parameter with time who i'm need wait for redo the call. My problem is to wait this time with an `AlertDialog` and call the API again. – rodrigomedeiros Jun 19 '17 at 14:03
-
If the the response land at onSuccess() if the response contains remaining time, show progress at dialog and start the thread at onSuccess which will resend the request after the remaining time. – Ait Bri Jun 19 '17 at 14:13
-
Thread.sleep inside in onSuccess() is a best practice for retry call? It seems weird. =/ – rodrigomedeiros Jun 19 '17 at 14:17
-
timer.schedule(new TimerTask() { @Override public void run() { // Your database code here } }, timeToResendRequestInMilliSecond); – Ait Bri Jun 19 '17 at 14:22
-
Resolved. But I believe there are more elegant solutions to do that. Thank you! – rodrigomedeiros Jun 19 '17 at 17:29
-
@rodrigomedeiros I believe custom callback would do the same job but at the end it will run the same code https://gist.github.com/facundomr/2362c57383368e9fd6cf – Ait Bri Jun 19 '17 at 19:19