简体   繁体   中英

Showing Dialog after another Dialog: HANGS

I have a really weird problem, which I am unable to debug so far... Thing is...my app needs to download something to work. So in the beginning of the onCreate() method, I check if that something is already downloaded. If not, I pop a dialog up asking the user to download it.

if (!isInstalled) {
            showDialog(DIALOG_INSTALL);
        } else {
            start();
        }

Where start() method performs some other action. Now, that showDialog calls this:

builder = new AlertDialog.Builder(MyApp.this);
        builder.setMessage("Would you like to install...")
        .setCancelable(false)
        .setPositiveButton("Install", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                dialog.dismiss();
                aManager.install(MyApp.this);
            }
        });
        dialog = builder.create();
        return dialog;

My dialog is shown and I am clicking, so aManager.install() is called. I am passing the context because that aManager.install() pops up a ProgressDialog to show downloading progress and spawns a new thread in which everything is downloaded. So obviously before creating my dialog I make a Handler to receive the response from that aManager.install(). And the response MAY vary, because for example the internet connection isn't available (Exception raised and catched and listener called with different code).

Now, when that happens (Exception) I would like to call another dialog saying "something went wrong, would you like to retry?"...so another call to showDialog(DIALOG_REINSTALL) (this time with another code). Thing is...the showDialog() gets called (I can verify this by logging) but the dialogs doesn't show up. Instead my application JUST HANGS!?!?!?

Does someone have a clue why it's doing this???? No exception raised, absolutely nothing from logcat, I can't tell WHERE it's hanging...just see that the method is called and the dialog should be displayed...

Thank you very much!!

Looks like you have a deadlock. I would put the download code on the separate thread eg use AsyncTask . In task.onPreExecute() you can dismiss 1st dialog and pop-up your progress dialog which you update by overwriting task.onProgressUpdate()

使用.show()而不是.create()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM