3

I am developing application on music player . I am facing error like.

'*.MusicPlayerTabWidget has leaked ServiceConnection *

Please gave you comments regarding this. I share my Logcat for this also.

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

More over that if you have any reference tutorials for the music player please share with me..

full Error
  • 308
  • 3
  • 8
  • 21

6 Answers6

7

Add unbindService(mConnection); in your onstop() method. The code will start working properly.

nhahtdh
  • 55,989
  • 15
  • 126
  • 162
user1398739
  • 216
  • 5
  • 8
3

If you are doing a local binding to the service inside you activity , you need to make sure that you are disconnecting from the service whenever your activity is getting closed. Otherwise the app will start leaking the connection as in your error.

Akhil
  • 13,888
  • 7
  • 35
  • 39
  • I know this is old question,But I need help ! Say if need service to be running in background android service we cant' call 'bindService(new Intent(IRecordService.class.getName()), mServiceConnection, Context.BIND_AUTO_CREATE);' ?? – LOG_TAG Dec 19 '13 at 11:35
  • What i have to do if I want keep alive the service in Pending Intent notification ? Ex:- I clicked on activity for recording Audio with Notification 'recording' If click back button if call 'unbindService, it will stop recoding!! do you I think I have to change "local binding to the service inside you activity" to startService http://stackoverflow.com/questions/3514287/android-service-startservice-and-bindservice – LOG_TAG Dec 19 '13 at 11:42
2

You're trying to show something after you're exit activity ( your thread came back ).

Krishnakant Dalal
  • 3,568
  • 7
  • 34
  • 62
0

as shown here, you should override the onDestroy and dismiss the dialog that is running after the activity closes.

Community
  • 1
  • 1
thepoosh
  • 12,497
  • 15
  • 73
  • 132
0

This can also happen when your Service has registered a BroadcastReceiver and didn't unregister.

So please unregister it in onDestroy

    unregisterReceiver(mReceiver);
Giridhar Bandi
  • 1,313
  • 1
  • 11
  • 28
0

If you bind to getApplicationContext() instead, the binding will run as long as your app is running. If you bind to getContext(), and the Activity's context is destroyed, android notices that you didn't close the connection related to that context.

npjohns
  • 2,218
  • 1
  • 17
  • 16