MediaController leaking on activity

I am using MediaPlayer and MediaController objects to stream audio. When closing the activity I am getting a window leaked exception.

I have the following in my activity which doesn't help at all.

@Override
protected void onStop() {
    super.onStop();
    mediaController.hide();

}

I get the following stack trace:

01-24 20:11:18.317: E/WindowManager(26286): Activity co.uk.ing_simmons.aberdeensoundsites.RecordingDetails has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@4182d590 that was originally added here 01-24 20:11:18.317: E/WindowManager(26286): android.view.WindowLeaked: Activity co.uk.ing_simmons.aberdeensoundsites.RecordingDetails has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@4182d590 that was originally added here 01-24 20:11:18.317: E/WindowManager(26286): at android.view.ViewRootImpl.(ViewRootImpl.java:418) 01-24 20:11:18.317: E/WindowManager(26286): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:294) 01-24 20:11:18.317: E/WindowManager(26286): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:226) 01-24 20:11:18.317: E/WindowManager(26286): at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:151) 01-24 20:11:18.317: E/WindowManager(26286): at android.view.Window$LocalWind owManager.addView(Window.java:547) 01-24 20:11:18.317: E/WindowManager(26286): at android.widget.MediaController.show(MediaController.java:470) 01-24 20:11:18.317: E/WindowManager(26286): at android.widget.MediaController.show(MediaController.java:429) 01-24 20:11:18.317: E/WindowManager(26286): at co.uk.ing_simmons.aberdeensoundsites.RecordingDetails$2.run(RecordingDetails.java:202) 01-24 20:11:18.317: E/WindowManager(26286): at android.os.Handler.handleCallback(Handler.java:615) 01-24 20:11:18.317: E/WindowManager(26286): at android.os.Handler.dispatchMessage(Handler.java:92) 01-24 20:11:18.317: E/WindowManager(26286): at android.os.Looper.loop(Looper.java:153) 01-24 20:11:18.317: E/WindowManager(26286): at android.app.ActivityThread.main(ActivityThread.java:5006) 01-24 20:11:18.317: E/WindowManager(26286): at java.lang.reflect.Method.invokeNative(Native Method) 01-24 20:11:18.317: E/WindowManager(26286): at java.lang.reflect.Method.invoke(Method.java:511) 01-24 20:11:18.317: E/Windo wManager(26286): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:821) 01-24 20:11:18.317: E/WindowManager(26286): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584) 01-24 20:11:18.317: E/WindowManager(26286): at dalvik.system.NativeStart.main(Native Method) 01-24 20:11:18.325: E/InputEventReceiver(26286): channel '41c81858 Panel:co.uk.ing_simmons.aberdeensoundsites/co.uk.ing_simmons.aberdeensoundsites.RecordingDetails (client)' ~ Publisher closed input channel or an error occurred. events=0x9

Which seems to point to line 202 which is this line:

mediaController.show();

I have been Googling this for hours now and literally everything says to put "mediaController.hide()" in the onStop method to prevent leaks. Which clearly isn't working so any help or guidance here would be greatly appreciated.

Thanks


You probably want to reverse the lines

super.onStop();
mediaController.hide();

to

mediaController.hide();
super.onStop();
链接地址: http://www.djcxy.com/p/86706.html

上一篇: 我的活动泄露了窗口,我找不到解决方案

下一篇: MediaController泄露活动