1
How do I limit the running time of a Asynctask
and return a warning when the limit is reached ?
The method searches a json of a webservice, but the same may be out of the air, and when this happens the app keeps trying for a long time until it gives the error.
protected String doInBackground(Void... params) {
StringBuilder content = new StringBuilder();
try {
URL url = new URL("endereco.com/dados.php");
URLConnection urlConnection = url.openConnection();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
String line;
while ((line = bufferedReader.readLine()) != null) {
content.append(line + "\n");
}
bufferedReader.close();
} catch (Exception e) {
e.printStackTrace();
}
I believe it would be the case to set a timeout at the time of opening the connection with the webservice
– Homer Simpson
@Henry would be here to serve this timeout
URLConnection urlConnection = url.openConnection();
?– rbz
That, rephrase the question and add the link code, which I try to formulate an answer.
– Homer Simpson
Amended question !
– rbz
Would that be:
urlConnection.setConnectTimeout()
right– rbz