如何检查当前活动前面是否有对话框? [英] How to check if the current activity has a dialog in front?

查看:78
本文介绍了如何检查当前活动前面是否有对话框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用第三方库,有时会弹出一个对话框.在完成当前活动之前,我想检查当前上下文中是否弹出对话框.

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.

是否有用于此的API?

Is there any API for this?

推荐答案

您可以检查它是否在该活动的活动片段上运行,并检查其中一个是否为DialogFragment,这意味着屏幕上存在活动对话框:

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

这篇关于如何检查当前活动前面是否有对话框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆