Here is the situation. My app runs fine, and is able to establish connections with URLs. BUT after a few hours of leaving the app running, all of a sudden the Facebook reque
java.net.UnknownHostException generally means the IP address of a host could not be resolved, although the actual cause may vary case-by-case. If the code is implemented properly (regardless of which API you use, HttpUrlConnection or DefaultHttpClient) and it is still happened intermittently, it is very likely a bug in old Android system related to DNS caching and TTL management:
Issue 7904: Android does not support TTL and caches DNS result for 10 minutes
This is fixed since Android 4.1, see the extra notes in InetAddress API Doc:
DNS caching
In Android 4.0 (Ice Cream Sandwich) and earlier, DNS caching was performed both by InetAddress and by the C library, which meant that DNS TTLs could not be honored correctly. In later releases, caching is done solely by the C library and DNS TTLs are honored.
For old Android version, Android suggests adjust Java level DNS properties networkaddress.cache.ttl and networkaddress.cache.negative.ttl, see JavaDoc in old source code:
/**
* ... ...
*
* DNS caching
* On Android, addresses are cached for 600 seconds (10 minutes) by default. Failed lookups are
* cached for 10 seconds. The underlying C library or OS may cache for longer, but you can control
* the Java-level caching with the usual {@code "networkaddress.cache.ttl"} and
* {@code "networkaddress.cache.negative.ttl"} system properties. These are parsed as integer
* numbers of seconds, where the special value 0 means "don't cache" and -1 means "cache forever".
*
* ... ...
*/
Related discussion:
Try adjusting those two properties and see if that makes any difference, if you are targeting on an old Android version.