views:

42

answers:

1

Is there a generic way to determine if there is dialog currently shown ? Sure, i can keep track of all createDialog and dismissDialog invocations, but that's cumbersome.

thanks

A: 

I use this method:

protected void showDialogSafe(int id) {
    if (!isFinishing()) {
        showDialog(id);
    }
}

Which I grabbed from here: http://daniel-codes.blogspot.com/2009/12/activities-and-dialogs.html

When dismissing them I just catch the IllegalArgumentException.

Falmarri, keeping track of the dialogs seems to be easier said than done when you have multiple threads running. I thought my code was perfect, but I get a bunch of crash reports when my app tries to dismiss dialogs that aren't shown or tries to display a dialog when the activity is finished.

Brandon