Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6925081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:44:39+00:00 2026-05-27T10:44:39+00:00

My application makes a HTTP request to retrieve an XML file and then translates

  • 0

My application makes a HTTP request to retrieve an XML file and then translates that into a ListView.
The problem is that when the View containing that list is opened the app freezes for a few seconds while the content is downloaded and parsed and translated onto the ListView. (But it works).

I have tried to implement an AsyncTask (see code below) to do the processing in a background thread, but my implementation has caused the app the freeze for a much longer time than before.

This involves three classes: MainActivity class; ListViewer class; and XMLhelper class. MainActivity just contains a Button to call the ListViewer. ListViewer is supposed to be the UI thread. XMLhelper contains functions to make the HttpClient request.

ListViewer.java (brief):

public class ListViewer extends ListActivity {

    private ArrayList<HashMap<String, String>> xmlList;
    private String server;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.list_view);

        xmlList = new ArrayList<HashMap<String, String>>();
        server = "http://www.myserver.com/xml";
        getXMLList();
    }

    public void getXMLList() {
        Document xmlDocument = XMLhelper.getXMLDocument(server);
        int numResults = XMLfunctions.numResults(xmlDocument);
        if (numResults <= 0) {
            Toast.makeText(this, "No results found.", Toast.LENGTH_LONG).show();
            finish();
        }

        NodeList nodes = xmlDocument.getElementsByTagName("result");
        for (int i=0; i<nodes.getLength(); i++) {
            HashMap<String, String> map = new HashMap<String, String>();
            Element e = (Element)nodes.item(i);
            map.put(...); //code omitted
            xmlList.add(map);
        }

        ListAdapter adapter = new SimpleAdapter(this, xmlList,
            R.layout.list_view_row,
            new String[] {...},
            new int[] {...});
        setListAdapter(adapter);
    }
}

XMLhelper.java (brief):

public class XMLhelper {
    public static class DownloadContentTask extends AsyncTask<String, Void, String> {
        DownloadContentTask(String... URLs) {
            this.execute(URLs);
        }
        @Override
        protected String doInBackground(String... URLs) {
            String xml = null;
            try {
                DefaultHttpClient httpClient = new DefaultHttpClient();
                HttpPost httpPost = new HttpPost(URLs[0]);
                HttpResponse httpResponse = httpClient.execute(httpPost);
                HttpEntity httpEntity = httpResponse.getEntity();
                xml = EntityUtils.toString(httpEntity);
            } catch (...) {
                xml = "..."; //all exceptions are caught
            }
            return xml;
        }
    }

    public static Document getXMLDocument(String server) {
        DownloadContentTask xmlTask = new DownloadContentTask(new String[] { server });
        String xml = "";
        try {
            xml = xmlTask.get();
        } catch (...) {
            //print errors
        }
        return XMLfromString(xml);
    }

    public static Document XMLfromString(String xml) { ... }
    public final static String getElementValue(Node elem) { ... }
    public static int numResults(Document doc) { ... }
    public static String getValue(Element item, String str) { ... }
}

I intended to make it so that when ListViewer is called from the MainActivity the ListView is unpopulated but the UI is shown immediately, and then as soon as the content is downloaded and parsed the ListView is updated.

What am I doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T10:44:39+00:00Added an answer on May 27, 2026 at 10:44 am

    Pretty simple, take a look at the get() method documentation:

    Waits if necessary for the computation to complete, and then retrieves its result.

    By calling get() in getXMLDocument you block the current thread (UI Thread) untill the async task is done.

    The async task should do the updates itself, invoke them in the UI thread, rather than return the information back to the caller from UI thread.

    And you should always read the documentation 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing a Java application that makes an HTTP Request to a web
I've some fishy application that makes HTTP requests to a website, i would like
I have an Zend–based application that uses long polling. Basically it makes a HTTP
I have a Objective-C class that makes an HTTP request and, after receiving a
I'm working on an app that makes several Http Request to a RESTFULL web
My Rails application makes use of Time.zone so that each user can set their
I have application that makes different queries with different results so the caching in
I have a web application that makes heavy use of the Session state to
We have a Linux application that makes use of OpenSSL's Python bindings and I
I have a PHP application that makes extensive use of Javascript on the client

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.