0

I want to show a progress dialog while I'm processing some user's request. This is my code and I don't see any good reason why the dialog is not appearing on screen.

 public void onGoClick(Button button) {
    ProgressDialog progressDialog = null;
    try {
        if (invalid) {
           //   Show error message
        } else {
            progressDialog = new ProgressDialog(getActivity());
            progressDialog.setIndeterminate(true);
            progressDialog.setMessage(getActivity().getResources().getString(R.string.user_wait_message));
            progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
            progressDialog.show();

            //  Do processing
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    } finally {
        progressDialog.dismiss();
    }
}

When I move the ProgressDialog declaration statement inside the try block and removes the dismiss method from finally block, I'm able to see the circular dialog on the screen, but when I change it like the above code, nothing comes on the screen. There is no async calls in the processing area, that's why I don't find anything buggy here. Any help is appreciated, thanks.

2 Answers2

1

Your Progress dialog is shown and then immediately dismissed. The finally block is executed directly after the try block.

Try to add an OnDismissListener to verify this for yourself.

Janusz
  • 187,060
  • 113
  • 301
  • 369
0

It is very weird as clean and build worked for me. I don't know if it's a bug in Android Studio (1.2) or something else. I really appreciate your answers as it was very helpful and I've learned a lot of things about async in android :)