Android java.net.UnknownHostException: Host not resolved (strategy question)

I have an Android code that uses a background process to regularly (e.g. hourly) connect to a content source on the Internet to check for updated content. Since new users download the application and launch it for the first time, it seems (and it just “seems like at the moment”) that in this first situation, since the DNS for our servers is not already cached on the device, this first series of connections fails with UnknownHostException : host not resolved. And, of course, the application again tries again and (again, “looks like”), it all works - perhaps because the OS managed to actually resolve the address.

So my questions are: (1) Do other Android developers also see this behavior with their deployed applications? For the first time, a series of "host unresolved" problems that work later. (2) Does anyone have a better strategy for "warming up the DNS" so that the first real connections work? or maybe you just tried some kind of rollback when you come across this exception? I considered a separate stream that tries to extract a small text file from our server, and it just loops until it receives it, and (possibly not sure about this part) blocks other outgoing network connections until it succeeds .

Anyway, I read a piece of answers to various similar questions here in Stack Overflow, and I just assured everyone that

<uses-permission android:name="android.permission.INTERNET" /> 

installed in my manifest file :)

+8
java android
Jul 20 '10 at 19:34
source share
1 answer

I came across this behavior when using HttpUrlConnection. I use a simple workaround - I execute the following code before using any URL.

  try { InetAddress i = InetAddress.getByName(URLName); } catch (UnknownHostException e1) { e1.printStackTrace(); } // ... actually using URLName 

I first got an UnknownHostException here, but the following uses of the URL are successful (the DNS server returns the correct IP address and I can connect to the server).

+14
Jul 21 '10 at 10:11
source share



All Articles