android - Android 中的 HttpResponse

标签 android httpresponse

我有一个问题,我想解析网络上的 XML 文件。现在我的 HttpResponce 读取该 XML 文件的时间太多了,所以我的 GUI 出现“成为运行时错误”错误。

try {

        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpPost httpPost = new HttpPost("http://chukk.nuzoka.com/name.xml");

        HttpResponse httpResponse = httpClient.execute(httpPost);

        HttpEntity httpEntity = httpResponse.getEntity();
        line = EntityUtils.toString(httpEntity);


    } catch (UnsupportedEncodingException e) {
        line = "<results status=\"error\"><msg>Can't connect to server</msg></results>";
    } catch (MalformedURLException e) {
        line = "<results status=\"error\"><msg>Can't connect to server</msg></results>";
    } catch (IOException e) {
        line = "<results status=\"error\"><msg>Can't connect to server</msg></results>";
    }

感谢任何帮助:)

最佳答案

作为 UI 编程的一般规则,不仅是 Android,您应该将任何繁重的处理/耗时任务转移到后台线程。

有很好的工具可以帮助您在后台执行长任务并将其最终/中间结果发布到 Android 中的 UI 线程,例如 AsyncTaskHandlers .

关于android - Android 中的 HttpResponse,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9457456/

相关文章:

java - 在 Android 1.5 上获取 Cell RSSI(网络信号强度)

android - 删除ImageView中的透明区域

java - 如何从 Spring Boot Controller 返回超链接?

java - HTTP/1.1 500 网页运行时出现内部服务器错误 Java

javascript - 如何从 Angular JS 中的 HttpResponse 中提取 JSON 数据?

java - 使用 Spring Boot 提供 gzip 压缩文件

java - 在主机运行时将不同的摄像头连接到主机

Java 安卓 : Pre-processing the UI before it displays

python - 如何从 POST 变量保存文件数据并将其加载回 Python Django 中的响应?

Android - 从自定义 View 中的 onTouch 方法向 mainActivity 发送信息