Activity has leaked window that was originally added

后端 未结 30 3256
野趣味
野趣味 2020-11-21 05:48

What is this error, and why does it happen?

05-17 18:24:57.069: ERROR/WindowManager(18850): Activity com.mypkg.myP has leaked window com.android.internal.pol         


        
30条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2020-11-21 06:22

    I was getting these logs in my video player application. These messages were thrown while the video player was closed. Interestingly, I used to get these logs once in a few runs in a random manner. Also my application does not involve in any progressdialog. Finally, I got around this issue with the below implementation.

    @Override
    protected void onPause()
    {
        Log.v("MediaVideo", "onPause");
        super.onPause();
        this.mVideoView.pause();
        this.mVideoView.setVisibility(View.GONE);
    }
    
    @Override
    protected void onDestroy()
    {
        Log.v("MediaVideo", "onDestroy");
        super.onDestroy();
    }
    
    @Override
    protected void onResume()
    {
        Log.v("MediaVideo", "onResume");
        super.onResume();
        this.mVideoView.resume();
    }
    

    Override the OnPause with call to mVideoView.pause() and the set visibility to GONE. This way I could resolve the "Activity has leaked window" log error issue.

提交回复
热议问题