Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if the current activity has a dialog in front?

Tags:

I am using a third-party library and sometimes it pops up a dialog. Before I finish the current activity, I want to check whether there is a dialog popped up in the current context.

Is there any API for this?

like image 393
newme Avatar asked Jun 14 '12 03:06

newme


1 Answers

You can check it running over the active fragments of that activity and checking if one of them is DialogFragment, meaning that there's a active dialog on the screen:

    public static boolean hasOpenedDialogs(FragmentActivity activity) {         List<Fragment> fragments = activity.getSupportFragmentManager().getFragments();         if (fragments != null) {             for (Fragment fragment : fragments) {                 if (fragment instanceof DialogFragment) {                     return true;                 }             }         }          return false;     } 
like image 51
Alécio Carvalho Avatar answered Sep 21 '22 15:09

Alécio Carvalho