tvbarthel / BlurDialogFragment

Library project to display DialogFragment with a blur effect.
Apache License 2.0
2.09k stars 334 forks source link

BlurredBackgroundView never removed from view heirarchy #7

Closed jacobtabak closed 9 years ago

jacobtabak commented 9 years ago

In BlurDialogEngine.onDismiss(), the blurred background view's visibility is set to View.GONE and the reference is nulled, however it's still part of the view heirarchy.

Next time you show the dialog, a new ImageView is added to the container activity's decor view.

If you put a breakpoint in PhoneWindow.addContentView(), you can see that mContentParent's child count increases steadily each time you open a dialog.

You can fix it doing something like this:

    public void onDismiss() {
        //remove blurred background and clear memory, could be null if dismissed before blur effect
        //processing ends
        if (mBlurredBackgroundView != null) {
            ViewGroup parentGroup = (ViewGroup)mBlurredBackgroundView.getParent();
            if (parentGroup != null) {
              parentGroup.removeView(mBlurredBackgroundView);
            }
            mBlurredBackgroundView = null;
        }

        //cancel async task
        mBluringTask.cancel(true);
        mBluringTask = null;
    }
tbarthel-fr commented 9 years ago

Hi @jacobtabak

Again, thanks a lot for your feedback (=

I never went so far in view heirarchy and I'm very grateful for having taught me something that I would probably never learn by myself!

Thanks to your feedback, I tried to understand a little bit more what realy does setVisibility(View.GONE) and in fact, it does not remove the view from the view heirarchy at all.

I will merge your pull request asap :D

One more time, a huge thanks for your very interesting feedback