Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

235
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda