Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

244
Views
Android Parsing a website with AsyncTask, urlConnection and InputStreamReader takes too long

I am trying to parse the following page with AsyncTask, urlConnection and InputStreamReader

public class DownloadTask extends AsyncTask<String, Void, String> {

    URL url;
    URLConnection urlConnection;
    String result = null;
    @Override
    protected String doInBackground(String... urls) {

        try {

            url = new URL(urls[0]);

            urlConnection = (URLConnection) url.openConnection();

            InputStream in = urlConnection.getInputStream();

            InputStreamReader reader = new InputStreamReader(in);

            int data = reader.read();

            while (data != -1) {
                char current = (char) data;

                result += current;
                data = reader.read();
            }
            return result;

        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }


        return null;
    }
}

And I am using this on this way:

        DownloadTask downloadTask = new DownloadTask();

    String data = null;
    try {

        data = downloadTask.execute("http://www.imdb.com/movies-in-theaters/").get();

    } catch (InterruptedException e) {
        e.printStackTrace();
    } catch (ExecutionException e) {
        e.printStackTrace();
    }

The problem is that it takes more than 3 mins to finish the DownloadTask. Finally after this time it works on the emulator but not in a real device.

I know that this is not a good way (parsing a web page) to do stuff like that, but I am doing it for educational reasons.

Any advice how I can speed up the procedure?

Thanks!

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!