I have multiple activities and one service. In MainActivity I successfully connect to service (using a class that implements ServiceConnection + bindService() + startService()) but when I try to apply same method in other activity I see in LogCat a error:
01-15 22:29:37.438: ERROR/ActivityThread(12206): android.app.ServiceConnectionLeaked:
Activity com.app.liviu.simpleMusicPlayer.PlaylistActivity has leaked ServiceConnection
com.app.liviu.simpleMusicPlayer.PlaylistActivity$CounterServiceConnection@43713c90
that was originally bound here.
Is it possible to connect to a service in an other way: something like to make static my CounterServiceConnection object in MainActivity and use it in the second one?
The error message is fairly self-explanatory: you are leaking a
ServiceConnection, by which Android means you are callingbindService()but are not callingunbindService(), and the activity that calledbindService()was destroyed. Make sure you callunbindService()inonDestroy(), if not sooner.No.