user3086708
user3086708

Reputation: 375

Show Dialog in Android produces crash

I hava a problem with a ProgressDialog in my App. I'm doing some tasks in background and notify actions to my Activity using a Handler. Sometimes, not always, when I try to show my Dialog app crashes and appears this exception:

android.view.windowleaked

The way of dialog is launched:

try {
    pd = new ProgressDialog(VoiceAcquisitionActivity.this);
    pd.setMessage("blablabla");
    pd.setCancelable(false);
    pd.show();
} catch (Exception e) {
    e.printStackTrace();
}

I've read and this exception is normal in .dismiss() operation but in .show()??

How can I avoid this problem?

Thanks

Upvotes: 0

Views: 410

Answers (1)

kandroidj
kandroidj

Reputation: 13922

for safety you could wrap your dialog logic in a block of code like:

   if(!isFinishing()){

       pd = newProgressDialog(VoiceAcquisitionActivity.this);                                 
       pd.setMessage("Loading message");
       pd.setCancelable(false);
       pd.show();
   }

Upvotes: 1

Related Questions