Android - MediaController泄露活动

时间:2014-01-24 07:25:31

标签: android memory-leaks android-mediaplayer mediacontroller

我使用MediaPlayer和MediaController对象来传输音频。关闭活动时,我得到一个窗口泄露异常。

我的活动中有以下内容,但根本没有帮助。

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

}

我得到以下堆栈跟踪:

  

01-24 20:11:18.317:E / WindowManager(26286):活动   co.uk.ing_simmons.aberdeensoundsites.RecordingDetails已泄露   window com.android.internal.policy.impl.PhoneWindow$DecorView@4182d590   最初添加到这里01-24 20:11:18.317:   E / WindowManager(26286):android.view.WindowLeaked:Activity   co.uk.ing_simmons.aberdeensoundsites.RecordingDetails已泄露   window com.android.internal.policy.impl.PhoneWindow$DecorView@4182d590   最初添加到这里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 $ LocalWindowManager.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 / WindowManager(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   面板:co.uk.ing_simmons.aberdeensoundsites / co.uk.ing_simmons.aberdeensoundsites.RecordingDetails   (客户端)'〜发布者关闭输入通道或发生错误。   事件= 0x9

这似乎指向第202行是这一行:

mediaController.show();

我一直在谷歌搜索这几个小时,字面意思是所有内容都说“在mediaStroller方法中放入”mediaController.hide()“以防止泄漏。这显然不起作用,因此非常感谢这里的任何帮助或指导。

由于

1 个答案:

答案 0 :(得分:1)

你可能想要反转这些行

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

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