I have come across this behaviour while using HttpUrlConnection. I am using simple workaround – I execute the following code just before using any url.
try {
InetAddress i = InetAddress.getByName(URLName);
} catch (UnknownHostException e1) {
e1.printStackTrace();
}
// ... actually using URLName
For the first time I obtain here UnknownHostException but next usages of the url are successful (DNS server returns proper IP address and I can connect to the server).