Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I was hoping the progress dialog would be displayed and remain displayed while the bitmap files were decoded. Also, I did not realize that the main thread in Android is the UI thread, and the UI is frozen while processing occurs on the main thread! I used a background thread and now the progress dialog is displayed correctly:</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"); BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inSampleSize = 16; File[] currentDirectoryFileList = currentDirectory.listFiles(); progressDialog.show(); readThumbnails(currentDirectoryFileList, opts); } private void readThumbnails(final File[] currentDirectoryFileList, final BitmapFactory.Options opts) { Thread backgroundThread = new Thread() { public void run() { try { 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"); } uiCallback.sendEmptyMessage(0); } catch(Exception ex) { Log.v("myLog", ex.toString()); } } }; backgroundThread.start(); } private Handler uiCallback = new Handler() { @Override public void handleMessage(Message emptyMessage) { progressDialog.dismiss(); } }; private class RowFileData { protected Bitmap rowBitmap; protected String rowFileName; RowFileData(Bitmap bitmapPreview, String fileName) { rowBitmap = bitmapPreview; rowFileName = fileName; } } </code></pre> <p>}</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.
    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