Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to determine whether it is possible to call a dialog.dismiss() without empty try-catch block?

I am getting the well known java.lang.IllegalArgumentException: View not attached to window manager. The currently known solution is to ignore the error using empty try-catch block. But is it there a more programmer friendly solution? E.g.

if (dialog.isAttached())
  dialog.dismiss();

Of course, better would be if the Android SDK would have a not failing function (because why the API should fail if it is impossible to avoid it??):

dialog.tryDismiss();

Or is the empty try-catch block architectonically justifiable? Or is it just a workaround for a bad or incomplete API?

like image 290
TN. Avatar asked Nov 05 '22 11:11

TN.


1 Answers

I always use:

if(dialog != null && dialog.isShowing())
  dialog.dismiss();
like image 88
SERPRO Avatar answered Nov 15 '22 05:11

SERPRO