Sunday 26 February 2012

Android: ProgressDialog does not show up

Android ProgressDialog can be used like iOS ActivityIndicator to show the app is blocked on some time-consuming work.

You cannot just show a ProgressDialog and then busy waiting a flag. If so the dialog will not show up. You need to busy wait in another thread.

Example:


final ProgressDialog dialog = ProgressDialog.show(
          MyActivity.this, "",
          "Loading. Please wait...", true);
new Thread(new Runnable() {
  public void run() {
    while (!isWorkDone)
      Thread.yield();
    dialog.dismiss();
  }
}).start();

No comments:

Post a Comment