views:

115

answers:

2

Hi! 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!!

A: 

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

DroidIn.net