Note that there are some explanatory texts on larger screens.

plurals
  1. POshow progressdialog when downloading bitmap
    primarykey
    data
    text
    <p>I want to show a progressbar downloading a bitmap:</p> <pre><code> public static Bitmap getBitmapFromURL(String src) { try { URL url = new URL(src); HttpURLConnection connection = (HttpURLConnection) url .openConnection(); connection.setDoInput(true); connection.connect(); InputStream input = connection.getInputStream(); int fileLength = connection.getContentLength(); // download the file byte data[] = new byte[1024]; long total = 0; int count; while ((count = input.read(data)) != -1) { total += count; // publishing the progress.... progressDialog.setProgress((int) (total * 100 / fileLength)); Log.i("progre+ss", (int) (total * 100 / fileLength) + " "); } Bitmap myBitmap = BitmapFactory.decodeStream(input); return myBitmap; } catch (IOException e) { e.printStackTrace(); return null; } } </code></pre> <p>which is initialised with:</p> <pre><code> private void openprogresdialog() { // TODO Auto-generated method stub progressDialog = new ProgressDialog(PrMapGen.this); progressDialog.setMessage("Generating File..."); progressDialog.setCancelable(false); progressDialog.setIndeterminate(false); progressDialog.setMax(100); progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); progressDialog.show(); new Thread() { public void run() { try { generatePrMap(DataArray, getIntent().getExtras().getString("project")); } catch (Exception e) { } progressDialog.dismiss(); projdata.close(); finish(); } }.start(); } </code></pre> <p>My problem is the following:</p> <p>when I use the while loop to update the progressbar, no image is returned, when I delete the while loop the bitmap is returned successfuly.</p> <p>Why???</p> <p>thanks in advance</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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