I have created a simple custom layout by extending ViewGroup. I create a Button and a PopupMenu on init(). If the button gets pressed, the PopupMenu gets shown. The problem is that, when the PopupMenu is showing, if I rotate the device, I get the following error message.
E/WindowManager: android.view.WindowLeaked: Activity has leaked window android.widget.PopupWindow$PopupDecorView{c44e7da V.E...... ......ID 0,0-392,960} that was originally added here
I have found a similar question (PopupMenu PopupWindow$PopupViewContainer leak), and the solution was calling dismiss() of the PopupMenu onStop(). However, since this is not an activity but a ViewGroup, I have no onStop(). So, I tried to find a similarly named event, and found onDetachedFromWindow(). I called dismiss() in onDetachedFromWindow().
onDetachedFromWindow() does get called before screen rotation, but I still get the WindowLeaked error message.
How can I solve this problem? Actually, it seems the application works fine and all I get is the error message in the log. Is this error ignorable?