A task: I should track visibility of whole Android application and generate events when it goes to background or foreground. First part of the task is completed: I have special global counter which I increment in Activity onStart() and decrement in Activity onStop(), when this counter downs to zero then my application has gone to background.
Second part of the task is tricker. I know about strange behavior of onResume() and advice to use onWindowFocusChanged(boolean). I looked into documentation of onWindowFocusChanged(boolean) and noticed such thing:
As a general rule, however, a resumed activity will have window focus... unless it has displayed other dialogs or popups that take input focus, in which case the activity itself will not have focus when the other windows have it. Likewise, the system may display system-level windows (such as the status bar notification panel or a system alert) which will temporarily take window input focus without pausing the foreground activity.
Is any way to check out: whose window is shown over resumed activity from my app? Is it my dialog or keyguard? Is any way to catch event: all but mine windows over resumed activities are removed?