Note that there are some explanatory texts on larger screens.

plurals
  1. POdownloading an image from internet (AsyncTask), takes too long
    text
    copied!<p>I'm using AsyncTask to perform an operation that connects to internet, download data, and then get a picture of the internet.</p> <p>The image obtained from internet too, but when it takes the server to respond the application gets a FC.</p> <p>How I can do to get the data AsyncTask although it takes the server?</p> <p>Then I put the code I use to download the data:</p> <pre><code>class CargaImgs extends AsyncTask&lt;Void, Void, Bitmap&gt; { final ProgressDialog progressDialog = new ProgressDialog(imagen.this); protected void onPreExecute() { progressDialog.setTitle(""); progressDialog.setMessage("Cargando Imagen..."); progressDialog.show(); } protected Bitmap doInBackground(Void... params) { return urlImageToBitmap(imageUrl(StrUrl)); } protected void onPostExecute(Bitmap imagen) { RawBmp = imagen; sourceBmp = RawBmp; sourceBmp = redimensionarImagenMaximo(sourceBmp, screen_w, screen_h); imageWidth = sourceBmp.getWidth(); imageHeight = sourceBmp.getHeight(); showBmp = Bitmap.createBitmap(sourceBmp); main.invalidate(); primera_carga = false; progressDialog.dismiss(); } } private String imageUrl(String url) { Document doc = null; try { doc = Jsoup.connect(url).get(); } catch (IOException e1) { e1.printStackTrace(); } Elements div_exterior = doc.getElementsByClass("inner"); for (Element subelementos : div_exterior) { Elements imgs = subelementos.getElementsByTag("img"); StrUrlImage = imgs.get(1).attr("src"); if (StrUrlImage == StrUrlImage2) { } else { return imgs.get(1).attr("src"); } } return null; } public Bitmap urlImageToBitmap(String urlImage) { Bitmap mIcon1 = null; URL url_value; try { url_value = new URL(urlImage); if (url_value != null) { mIcon1 = BitmapFactory.decodeStream(url_value.openConnection() .getInputStream()); } } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return mIcon1; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload