3

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

'* .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

此外,如果您有任何音乐播放器的参考教程,请与我分享..

4

6 回答 6

7

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

于 2012-08-30T08:05:11.523 回答
3

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

于 2012-05-01T06:23:24.380 回答
2

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

于 2012-05-01T05:23:44.140 回答
0

如此处所示您应该覆盖onDestroy并关闭活动关闭后正在运行的对话框。

于 2012-05-01T06:27:24.707 回答
0

当您的 Service 注册了 BroadcastReceiver 并且没有取消注册时,也会发生这种情况。

所以请在 onDestroy 中取消注册

    unregisterReceiver(mReceiver);
于 2014-03-24T10:03:25.183 回答
0

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

于 2017-04-30T00:20:46.650 回答