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

后端 未结 8 1855
自闭症患者
自闭症患者 2021-02-05 09:37

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 con

8条回答
  •  离开以前
    2021-02-05 10:18

    I faced a similar problem, and did not want to modify all locations where dialogs were being created and shown. My solution was to look at whether the view I was showing had window focus via the hasWindowFocus() method. This will not work in all situations, but worked in my particular case (this was for an internal recording app used under fairly restricted circumstances).

    This solution was not thoroughly tested for robustness but I figured I would post in in case it helped somebody.

提交回复
热议问题