0

Over the last couple days I have been programming an android app (With Android Studio), collecting JSON data to use through an externally provided API. However, I have found that, occasionally, my program refused to collect this information due to refusing to connect to the API service. This because I have found that (likely due to authentication) accessing the API can sometimes take time of up to 5 seconds to retrieve all data. While the app does seem to keep running trying to fetch the data, my logs state that connection is broken down after trying to connect for a few seconds.

As I have no control over the external provider and my app requires their service, I am forced to find a way to increase the timeout before the connection shuts down. I fail to find what may be used to do this or what could be used to circumvent this problem.

Any help would be appreciated.

  • What are you using to make the request? HttpUrlConnection has a timeout setting. See this post http://stackoverflow.com/questions/2799938/httpurlconnection-timeout-question – TyndieRock Dec 29 '14 at 15:12
  • I'm using a HttpGet- After a bit of searching I did however indeed find that this is the exact location you should declare such timeout, as a similar example here shows: http://stackoverflow.com/questions/12270601/setting-a-timeout-value-when-retrieving-data-via-httpget-object With the few tests I've run so far with the increased time-out, I haven't encountered any problems. So thanks, I believe that solved my issue. – Nick Sterckx Dec 29 '14 at 16:26

1 Answers1

0

As posted above, you declare the timeout you want to use as a parameter during the request. As I was using HttpGet, the method I had to use to include this parameter is described further here: Setting a timeout value when retrieving data via HttpGet object

Community
  • 1
  • 1