The Android Progress dialog box does not appear

advertisements

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.


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.