1
我使用下面的代碼從http服務器檢索一些文本。尺寸小於1 kB並在0.002毫秒內生成Android的url.openStream慢?
但是,檢索數據可能需要600毫秒,但大多數時間爲2000到5000毫秒。
以下代碼用於:
long starttime = System.currentTimeMillis();
StringBuffer SB = new StringBuffer();
Common.toLog("101 took "+ (System.currentTimeMillis() - starttime) + " ms");
try {
URL url = new URL(Common.server+request);
Common.toLog("102 took "+ (System.currentTimeMillis() - starttime) + " ms");
InputStreamReader ISR = new InputStreamReader(url.openStream());
Common.toLog("102a took "+ (System.currentTimeMillis() - starttime) + " ms");
BufferedReader in = new BufferedReader(ISR);
Common.toLog("103 took "+ (System.currentTimeMillis() - starttime) + " ms");
String inputLine;
while ((inputLine = in.readLine()) != null) {
SB.append(inputLine);
}
in.close();
Common.toLog("105 took "+ (System.currentTimeMillis() - starttime) + " ms");
} catch (IOException e)
{
Common.toLog("Could not make connection 1");
showMSG(R.string.ERROR_NO_INTERNET, true);
}
最費時的方法是對數點102和點102A之間。當使用鉻我可以加載the page在300-350毫秒。我想知道是否有更高效的方法來檢索此數據
它比以前更好,使用下面的腳本: http://androidforums.com/application-development/9261-doing-http-request-android。 html但是:第一個請求的響應時間仍然需要1600毫秒,而下一個請求的響應時間爲+/- 700秒 –