I have a stream that connects to a url to receive some data.
Sometimes the httpConnection.connect(); method httpConnection.connect(); spent too much time to get an answer, and I want to limit the download dialog of this connection flow to 5 segments.
I tried adding timeouts to the code , but it does not work !!
URL formattedUrl = new URL(url); URLConnection connection = formattedUrl.openConnection(); connection.setConnectTimeout(5000); connection.setReadTimeout(5000); HttpURLConnection httpConnection = (HttpURLConnection) connection; httpConnection.setAllowUserInteraction(false); httpConnection.setInstanceFollowRedirects(true); httpConnection.setRequestMethod("GET"); httpConnection.setConnectTimeout(5000); httpConnection.setReadTimeout(5000); httpConnection.connect();
So, I have to stop the connection method and the stream when 5000 seconds have passed or when the used one has pressed the back key on the phone.
How can this be achieved? I can not find information about this work in android with the url connection thread.
thanks
source share