Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid BitmapFactory decodeFile is called before it should be
    primarykey
    data
    text
    <p>I am trying to display thumbnails of images in a ListView. The images are located in the Camera folder on my SDCard. I am using BitmapFactory.decodeFile to read in the images. I would like to display a ProgressDialog while the files are being decoded. I am trying to show the ProgressDialog first and then call decodeFile in a for loop. The ProgressDialog is not being displayed until after the for loop. The call to decodeFile appears to be running before the ProgressDialog is displayed. </p> <p>How can I display the ProgressDialog before my for loop?</p> <p>public class ActivityProgressBar extends ListActivity {</p> <pre><code>private Vector&lt;RowFileData&gt; fileDataDisplay = null; RowFileData fileData; ProgressDialog progressDialog = null; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.list); progressDialog = new ProgressDialog(this); progressDialog.setMessage("Loading thumbnails..."); fileDataDisplay = new Vector&lt;RowFileData&gt;(); File currentDirectory = new File("/mnt/sdcard/dcim/camera"); File[] currentDirectoryFileList = currentDirectory.listFiles(); BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inSampleSize = 16; progressDialog.show(); for(int i=0; i&lt;currentDirectoryFileList.length; i++) { File currentDirectoryFile = currentDirectoryFileList[i]; fileData = new RowFileData(BitmapFactory.decodeFile(currentDirectoryFile.getPath(), opts), currentDirectoryFile.getPath()); fileDataDisplay.add(fileData); Log.v("myLog", "inside for loop"); } } private class RowFileData { protected Bitmap rowBitmap; protected String rowFileName; RowFileData(Bitmap bitmapPreview, String fileName) { rowBitmap = bitmapPreview; rowFileName = fileName; } } </code></pre> <p>}</p> <p>I've commented out the call to progressDialog.dismiss() in order to verify that the ProgressDialog was being shown after the for loop. I've removed the lines of code to display the images in the ListView for easier reading. I verified I was still in the for loop with my Log.</p> <p>Thanks</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.
    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