我正在使用 的实例URLConnection
从 Web 服务器下载图片。这适用于大多数手机。
我使用http://mindtherobot.com/blog/159/android-guts-intro-to-loopers-and-handlers/作为并行下载的灵感。
我同时调用两者setConnectTimeout(timeout)
,setReadTimeout(timeout)
以便在启动多个并行获取图像的线程时从超时中恢复。
在三星 Galaxy s2 手机上,超时被忽略,一些线程下载挂起几分钟,然后抛出异常并重试下载 - 下载第二次成功。
抛出的异常如下所示:
DownloadTask, network timeout (attempt #0)
java.net.SocketTimeoutException: failed to connect to host (port 80) after 1000ms
at libcore.io.IoBridge.connectErrno(IoBridge.java:150)
libcore.io.IoBridge.connect(IoBridge.java:112)
java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
java.net.PlainSocketImpl.connect(PlainSocketImpl.java:459)
java.net.Socket.connect(Socket.java:842)
libcore.net.http.HttpConnection.<init>(HttpConnection.java:77)
libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:351)
libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:86)
libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:308)
libcore.net.http.HttpEngine.connect(HttpEngine.java:303)
libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:282)
libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:232)
libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:80)
..
这是三星 Galaxy s2 上已知的损坏行为吗?
安卓版本:4.0.4。