Android Audio Service已泄露服务连接

时间:2012-05-01 05:15:17

标签: android logcat android-audiomanager

我正在开发音乐播放器的应用程序。 我面临的错误就像。

'* .MusicPlayerTabWidget已泄露ServiceConnection *

请对此发表评论。 我也分享了我的 Logcat

05-01 10:38:03.226: W/KeyCharacterMap(4225): Using default keymap
05-01 10:38:03.429: E/ActivityThread(4225): Activity com.pvMusic.pvm.MusicPlayerTabWidget has leaked ServiceConnection com.pvMusic.pvm.MusicPlayerTabWidget$1@4051c6f0 that was originally bound here
05-01 10:38:03.429: E/ActivityThread(4225): android.app.ServiceConnectionLeaked: Activity com.pvMusic.pvm.MusicPlayerTabWidget has leaked ServiceConnection com.pvMusic.pvm.MusicPlayerTabWidget$1@4051c6f0 that was originally bound here
05-01 10:38:03.429: E/ActivityThread(4225):     at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:938)
05-01 10:38:03.429: E/ActivityThread(4225):     at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:833)
05-01 10:38:03.429: E/ActivityThread(4225):     at android.app.ContextImpl.bindService(ContextImpl.java:879)
05-01 10:38:03.429: E/ActivityThread(4225):     at android.content.ContextWrapper.bindService(ContextWrapper.java:347)
05-01 10:38:03.429: E/ActivityThread(4225):     at com.pvMusic.pvm.MusicPlayerTabWidget.onStart(MusicPlayerTabWidget.java:175)
05-01 10:38:03.429: E/ActivityThread(4225):     at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1129)
05-01 10:38:03.429: E/ActivityThread(4225):     at android.app.Activity.performStart(Activity.java:3791)
05-01 10:38:03.429: E/ActivityThread(4225):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1624)
05-01 10:38:03.429: E/ActivityThread(4225):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
05-01 10:38:03.429: E/ActivityThread(4225):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
05-01 10:38:03.429: E/ActivityThread(4225):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
05-01 10:38:03.429: E/ActivityThread(4225):     at android.os.Handler.dispatchMessage(Handler.java:99)
05-01 10:38:03.429: E/ActivityThread(4225):     at android.os.Looper.loop(Looper.java:130)
05-01 10:38:03.429: E/ActivityThread(4225):     at android.app.ActivityThread.main(ActivityThread.java:3687)
05-01 10:38:03.429: E/ActivityThread(4225):     at java.lang.reflect.Method.invokeNative(Native Method)
05-01 10:38:03.429: E/ActivityThread(4225):     at java.lang.reflect.Method.invoke(Method.java:507)
05-01 10:38:03.429: E/ActivityThread(4225):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
05-01 10:38:03.429: E/ActivityThread(4225):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
05-01 10:38:03.429: E/ActivityThread(4225):     at dalvik.system.NativeStart.main(Native Method)
05-01 10:39:31.859: D/dalvikvm(4225): GC_EXPLICIT freed 166K, 46% free 3022K/5575K, external 557K/1031K, paused 52ms
05-01 10:39:31.906: D/dalvikvm(4225): GC_CONCURRENT freed 0K, 46% free 3022K/5575K, external 557K/1031K, paused 4ms+3ms

更多内容如果您有音乐播放器的参考教程,请与我分享..

6 个答案:

答案 0 :(得分:7)

unbindService(mConnection);方法中添加onstop()。代码将开始正常工作。

答案 1 :(得分:3)

如果您正在对活动中的服务进行本地绑定,则需要确保在活动关闭时断开与服务的连接。否则,应用程序将像您的错误一样开始泄漏连接。

答案 2 :(得分:2)

您正在尝试在退出活动后显示某些内容(您的主题回来了)。

答案 3 :(得分:0)

here所示,您应该覆盖onDestroy并关闭活动结束后运行的对话框。

答案 4 :(得分:0)

当您的服务注册了BroadcastReceiver但未注销时,也会发生这种情况。

所以请在onDestroy中取消注册

    unregisterReceiver(mReceiver);

答案 5 :(得分:0)

如果您绑定到getApplicationContext(),只要您的应用正在运行,绑定就会运行。如果绑定到getContext(),并且销毁了Activity的上下文,则android会注意到您没有关闭与该上下文相关的连接。