2

I'm having trouble with the following error displaying in my app:

"E/WindowManager: android.view.WindowLeaked: Activity com.awt.myapp.MyList has leaked window android.widget.PopupWindow$PopupDecorView{84fdb1f V.E...... .......D 0,0-369,120} that was originally added here..."

Basically I've got a recyclerview and in the adapter I have a bunch of textviews in each row and am binding click listeners to them, as clicking one of these textviews brings up a popup window. The problem is if I hit the Android back button while a popup is still visible the above error appears.

I understand that in my activity that holds the recyclerview I can add an 'onBackPressed()' method, but from here I'm not sure how to get a reference to any of the popup windows within the adapter (and close it at this stage) as I believe this is what I need to do.

Below is my click listener code, I've experimented with some options and having setFocusable just causes the back button to stop working so not sure if that's needed.

tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View moreInfoView) {

                myPopupWindow.setBackgroundDrawable(new ColorDrawable());
                //myPopupWindow.setFocusable(true);
                myPopupWindow.setTouchable(false);    // Ignores taps
                myPopupWindow.setOutsideTouchable(true);  // Disappear when tapping anywhere on screen
                int position = -tv.getHeight();
                myPopupWindow.showAsDropDown(tv, 0, position); 
                ((MyList) context).onToggleMoreInfo("show");
                myPopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
                    @Override
                    public void onDismiss() {
                        ((MyList) context).onToggleMoreInfo("hide");
                    }
                });                  
            }
        });

Hopefully this makes sense, if you need any more info let me know. Any advice would be appreciated.

Loop77
  • 98
  • 6

1 Answers1

0

If you create a listener on your adapter that implements the activity and calls it when you click on the item, you can export popup window logic to activity and override on back pressed to dimiss it.

Daniel RL
  • 353
  • 1
  • 12
  • Okay, going to look into how to go about doing that, may come back with questions :D Thanks. – Loop77 Jul 02 '17 at 06:11