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秒 –