2012-10-05 30 views

回答

3

這取決於android的版本。

如果您有Internet連接,並且您的應用程序聲明它需要在清單文件中訪問Internet,那麼地址應該沒有任何問題地解決。

http://developer.android.com/reference/java/net/InetAddress.html

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.

所以,如果你所要求的地址不超過生存時間年紀大了,緩存會回答。如果它不在緩存中或已過期,則操作系統將嘗試通過轉到DNS服務器來查找它。只有當您的Internet連接未啓動,或者沒有DNS響應時,纔會拋出異常,而不是緩存請求失敗時。

也就是說,如果你正在編寫你的老應用程序的應用程序,那麼這個問題可能會糾纏你。

有辦法對付它:
Android: Flush DNS