I have the following code which uses a VideoView and MediaController:
FrameLayout frameLayout = findViewById(R.id.frameLayout);
VideoView videoView = findViewById(R.id.videoView);
mediaController = new MediaController(this) {
@Override
public void hide() {
// do not hide
}
public boolean dispatchKeyEvent(KeyEvent event) {
if (event.getKeyCode() == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP) {
((Activity) getContext()).finish();
}
return super.dispatchKeyEvent(event);
}
};
mediaController.setAnchorView(frameLayout);
videoView.setMediaController(mediaController);
videoView.setVideoPath("android.resource://" + getPackageName() + "/" + R.raw.meditation);
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
mediaController.show(0);
}
}, 100);
The problem is when the activity finishes, I get the following error in my log:
10-28 05:57:16.075 6535-6535/com.kjdion.anxietynow E/WindowManager: android.view.WindowLeaked: Activity com.kjdion.anxietynow.MeditationActivity has leaked window DecorView@13fd277[] that was originally added here at android.view.ViewRootImpl.(ViewRootImpl.java:485) at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:346) at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:93) at android.widget.MediaController.show(MediaController.java:364) at com.kjdion.anxietynow.MeditationActivity$2.run(MeditationActivity.java:53) at android.os.Handler.handleCallback(Handler.java:790) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6494) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Despite this error, everything works perfectly.
Why is this happening and how do I fix it?