2

我创建了一个显示弹出窗口的活动。活动停止后,将打印以下消息以记录:

10-22 13:36:05.539: E/WindowManager(14865): android.view.WindowLeaked: Activity qnd.papaya.counter.gui.payment.PaymentActivity has leaked window android.widget.LinearLayout{430ac2a0 V.E..... ......I. 0,0-821,306} that was originally added here
10-22 13:36:05.539: E/WindowManager(14865):     at android.view.ViewRootImpl.<init>(ViewRootImpl.java:346)
10-22 13:36:05.539: E/WindowManager(14865):     at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:248)
10-22 13:36:05.539: E/WindowManager(14865):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
10-22 13:36:05.539: E/WindowManager(14865):     at android.widget.PopupWindow.invokePopup(PopupWindow.java:1019)
10-22 13:36:05.539: E/WindowManager(14865):     at android.widget.PopupWindow.showAtLocation(PopupWindow.java:850)
10-22 13:36:05.539: E/WindowManager(14865):     at android.widget.PopupWindow.showAtLocation(PopupWindow.java:814)
10-22 13:36:05.539: E/WindowManager(14865):     at qnd.papaya.counter.controller.PaymentPanelController.showPaymentTypesPopup(PaymentPanelController.java:188)
10-22 13:36:05.539: E/WindowManager(14865):     at qnd.papaya.counter.controller.PaymentPanelController.access$2(PaymentPanelController.java:159)
10-22 13:36:05.539: E/WindowManager(14865):     at qnd.papaya.counter.controller.PaymentPanelController$3.onClick(PaymentPanelController.java:197)
10-22 13:36:05.539: E/WindowManager(14865):     at android.view.View.performClick(View.java:4438)
10-22 13:36:05.539: E/WindowManager(14865):     at android.view.View$PerformClick.run(View.java:18422)
10-22 13:36:05.539: E/WindowManager(14865):     at android.os.Handler.handleCallback(Handler.java:733)
10-22 13:36:05.539: E/WindowManager(14865):     at android.os.Handler.dispatchMessage(Handler.java:95)
10-22 13:36:05.539: E/WindowManager(14865):     at android.os.Looper.loop(Looper.java:136)
10-22 13:36:05.539: E/WindowManager(14865):     at android.app.ActivityThread.main(ActivityThread.java:5001)
10-22 13:36:05.539: E/WindowManager(14865):     at java.lang.reflect.Method.invokeNative(Native Method)
10-22 13:36:05.539: E/WindowManager(14865):     at java.lang.reflect.Method.invoke(Method.java:515)
10-22 13:36:05.539: E/WindowManager(14865):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
10-22 13:36:05.539: E/WindowManager(14865):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
10-22 13:36:05.539: E/WindowManager(14865):     at dalvik.system.NativeStart.main(Native Method)

因此,我想关闭活动的 onPause() 方法中的弹出窗口。

有没有办法在活动中获取对所有可见 PopupWindows 的引用?就像是:

@Override
protected void onPause() {
    super.onPause();
    findPopupWithTag("MY_POPUP").dismiss(); // <--- IS THERE A SIMILAR METHOD?
}

我不想保留对弹出窗口的明确引用以保持我的代码简洁明了...

4

1 回答 1

0

看起来这是不可能的

如果你看看里面的PopupWindow.invokePopup方法,它看起来像这样

private void invokePopup(WindowManager.LayoutParams p) {
    ...
    mWindowManager.addView(mPopupView, p);
    ...
}

根据这个问题不可能View通过WindowManagerid找到

于 2015-09-09T18:42:06.657 回答