-2

The following warning message arises on API 23, 24 or 25 devices on device orientation changes from Portrait to Landscape (and vice versa) while the the Settings (options menu) is open. In both cases I have this error message in my log:

E/WindowManager: android.view.WindowLeaked: Activity com.example.test.myapplication.MainActivity has leaked window android.widget.PopupWindow$PopupDecorView{6bb10b1 V.E...... ......ID 0,0-686,168} that was originally added here at android.view.ViewRootImpl.(ViewRootImpl.java:368) at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:299) at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:85) at android.widget.PopupWindow.invokePopup(PopupWindow.java:1258) at android.widget.PopupWindow.showAsDropDown(PopupWindow.java:1110) at android.support.v7.widget.AppCompatPopupWindow.showAsDropDown(AppCompatPopupWindow.java:105) at android.support.v4.widget.PopupWindowCompatKitKat.showAsDropDown(PopupWindowCompatKitKat.java:30) at android.support.v4.widget.PopupWindowCompat$KitKatPopupWindowImpl.showAsDropDown(PopupWindowCompat.java:129) at android.support.v4.widget.PopupWindowCompat.showAsDropDown(PopupWindowCompat.java:206) at android.support.v7.widget.ListPopupWindow.show(ListPopupWindow.java:722) at android.support.v7.view.menu.StandardMenuPopup.tryShow(StandardMenuPopup.java:160) at android.support.v7.view.menu.StandardMenuPopup.show(StandardMenuPopup.java:187) at android.support.v7.view.menu.MenuPopupHelper.showPopup(MenuPopupHelper.java:290) at android.support.v7.view.menu.MenuPopupHelper.tryShow(MenuPopupHelper.java:175) at
...

I saw some questions here, on SO, but it seems to me that everyone just took the workaround and have overridden onStop() or onBackPressed() in main activity.

To test and debug, I have created a simple project with the AS wizard (with Navigation Drawer Activity option activated, so there is an Options Menu already incorporated). The only thing added/changed was:

android:configChanges="orientation|keyboardHidden" 

in the manifest file, but I am still having the same warning.

Vega
  • 27,856
  • 27
  • 95
  • 103
  • 1
    http://stackoverflow.com/questions/2850573/activity-has-leaked-window-that-was-originally-added goto this link it may help you. – Raseem Ayatt Oct 31 '16 at 10:05
  • 1
    The answers are for a project with some code in it. I consider that a project created with the wizard with no changes and with a simple use as open a menu and turn the device should not produce an error. I am thinking more of a bug. – Vega Oct 31 '16 at 10:15
  • 1
    add it in your amnifest – Raseem Ayatt Oct 31 '16 at 10:35
  • Added android:configChanges="orientation|keyboardHidden" in the manifest file , but still get the same error – Vega Oct 31 '16 at 11:16

2 Answers2

0

This was indeed a bug. I reported and it had been since fixed by Google. It can be followed here

Vega
  • 27,856
  • 27
  • 95
  • 103
  • It seems the didnt fix it. I still get this in API 23,25,27 in both emulator and real device – Nick Sep 20 '18 at 09:16
  • That's strange... Could it be a regression? I didn't check for a while, but at the time I posted this, it was fixed for my apps – Vega Sep 20 '18 at 09:21
  • I dont know either. I posted my problem here https://stackoverflow.com/questions/52419585/activity-has-leaked-window-android-widget-popupwindow-api-27?noredirect=1#comment91783979_52419585. You can check it again and let me know – Nick Sep 20 '18 at 09:23
  • Mine still works, but I return true in onCreateOptionsMenu() – Vega Sep 20 '18 at 09:35
  • 1
    I also tried that, but nothing. I did the simplest thing. Create a new project with basic activity. Run it, open the menu and rotate. I mean its all generic code nothing custom. – Nick Sep 20 '18 at 09:37
  • I did the same when debugging mine. It's just after trying that that I reported the bug... Have you tried restarting the emulator or reinstalling? I know it's trivial but who knows – Vega Sep 20 '18 at 09:38
  • 1
    The thing is, that happens in my real device too with oreo android. So i dont think its the emulator. I will give it a try though – Nick Sep 20 '18 at 09:39
  • Yes, could be an other option for debugging to test in the emulator :) – Vega Sep 20 '18 at 09:49
0

Please try this.

  android:configChanges="screenSize|orientation|keyboardHidden"
Pratik
  • 97
  • 1
  • 11