简体   繁体   中英

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

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();
   }

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