Search code examples
androidwindowfocusandroid-support-libraryandroid-alertdialog

Android AlertDialog leftover window blocking input after dismiss


I'm developing an Amazon FireTV app the relies on popup menus implemented as custom AlertDialogs. For styling reasons i'm using appcompat-v7:25.3.1

Currently I'm having trouble debugging this issue I run into: If i open and dismiss my dialog 2 times a window gets leaked, blocking the Amazon remote input events. I then need to press the back button (which closes the window) for the app to react correctly again.

Looking at Android Studio's LayoutInspector I can see the second, overlaying window is of this class: android.support.v7.app.AppCompatDelegateImplV9$ListMenuDecorView@1b4b8967

The logcat shows following entries (filtered by "Window")

04-04 13:49:28.429 1906-2324/? V/WindowManager: not Base app: Adding window 
Window{3663d4c0 u0 foo.bar/foo.bar.MainActivity} at 5 of 7
04-04 13:49:29.650 1906-2366/? W/InputMethodManagerService: Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@36117cec attribute=null, token = android.os.BinderProxy@348376a7
04-04 13:49:30.732 1906-2348/? V/WindowManager: not Base app: Adding window Window{2b864b4a u0 foo.bar/foo.bar.MainActivity} at 5 of 7
04-04 13:49:30.732 1906-2378/? V/WindowManager: Adding window Window{300f7bd8 u0 SubPanel:foo.bar/foo.bar.MainActivity} at 5 of 8 (after Window{164a9754 u0 foo.bar/foo.bar.MainActivity})

I am doing all my work off of one activity (MainActivity), which I use as context for every alertdialog i show. I am NOT using DialogFragments, cause i don't need fancy lifecycle handling for a popup menu.

Would be glad if someone could point me to the right direction!


Solution

  • So i found the cause of the problem:

    I forgot to return true after receiving the menu button event, meaning not marking it as consumed. Since i was using an AppCompatActivity without setting or displaying an actionbar for some reason appcompat tried to display a menu and overlayed a transparent window on top, which then was still visible after dismissing the dialogs.

    Logn story short: always return true after consuming a key event ;)