【发布时间】:2011-04-20 11:20:08
【问题描述】:
我正在为 Android 制作应用程序。我喜欢尽快打完剩下的电话。当我以 XML 形式获得结果时,需要 5 秒(!)才能获得这样的简单 xml:
<souvenirs>
<souvenir>
<id>1</id>
<name>Example 1</name>
<rating>3.4</rating>
<photourl>/images/example.jpg</photourl>
<price>3.50</price>
</souvenir>
<souvenir>
<id>2</id>
<name>Example 2</name>
<rating>2.4</rating>
<photourl>/images/example.jpg</photourl>
<price>8.50</price>
</souvenir>
</souvenirs>
所以我尝试使用 JSON。但这也需要大约 5 秒钟的时间来检索。
我使用以下代码在 android 中加载 XML:
URL url = new URL("http://example.nu?method=getAllSouvenirs");
URLConnection conn = url.openConnection();
long t=System.currentTimeMillis();
InputStream ins = conn.getInputStream();
Log.d("info", String.valueOf((System.currentTimeMillis()-t)));
日志说获取输入流大约需要 5000 毫秒。有什么方法可以加快速度吗?有人知道 Android Market 使用哪种技术吗?这比我的应用加载速度更快..
提前致谢! :)
【问题讨论】:
-
你确定服务器不是问题,因为它太慢了?
标签: android xml json rest google-play