Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

236
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda