Reputation: 3928
I am facing an interesting problem with HTTPUrlConnection on Android.
Here are the steps
1. Create a new HTTPUrlConnection with a particular url say URL
2. Now I change the APN settings on device level
3. Now I create another HTTPUrlConnection with the same URL.
When trying to read input steam after step 3, connection times-out.
Another interesting thing is When I change the URL in step 3 everything seems to work fine
One reason I can think of can be Android somehow keeps previous connection alive and returns me the same connection in step 3 and since the APN is changed, that connection is no more valid.
Any Insights in this will be greatly appreciated.
Thanks, Manan
Upvotes: 0
Views: 1635
Reputation: 1006674
One reason I can think of can be Android somehow keeps previous connection alive and returns me the same connection in step 3 and since the APN is changed, that connection is no more valid.
That is a very distinct possibility. Android added keep-alive support to HttpUrlConnection
. Normally, APN settings don't change (AFAIK), so this may not be a big problem. However, you can disable keep-alive via System.setProperty("http.keepAlive", "false");
, according to this Android Developer Blog post.
Upvotes: 1