ProgressDialog

Although a ProgressDialog is an AlertDialog, is not created with an AlertDialog.Builder. There is no STYLE_VERTICAL, only STYLE_HORIZONTAL and STYLE_SPINNER. See Android’s tutorial.

The main thread creates a ProgressThread to move the ProgressDialog and brighten the background of the LinearLayout from black to white. When the level of progress reaches 100, the main thread causes the ProgressDialog to break out of its for loop. This causes the ProgressThread to reach the end of its run method, which terminates the thread. The background becomes white suddenly because the background is dimmed down while the dialog is displayed.

Source code in Progress.zip

  1. ProgressActivity.java
  2. ProgressThread.java
  3. main.xml
  4. AndroidManifest.xml

Another example: ApiDemos/App/Alert Dialogs/Progress dialog

  1. AlertDialogSamples.java: case DIALOG_PROGRESS.
  2. alert_dialog.xml
  3. strings.xml

Things to try

  1. Change the style from STYLE_HORIZONTAL to STYLE_SPINNER. The ring never stops rotating, so the screenshot caught the hardware in the process of repainting the screen. Increasing the number of milliseconds passed to sleep didn’t help at all.


  2. Instead of dismissing the dialog as soon as the count reaches max, keep the dialog visible for three seconds.

  3. If the user presses the Android back button, change the background back to black. This is complicated because even after setting the state of the thread to false, the thread might still send one final message.