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 calling bindService()
but are not calling unbindService()
, and the activity that called bindService()
was destroyed. Make sure you call unbindService()
in onDestroy()
, if not sooner.
something like to make static my CounterServiceConnection object in MainActivity and use it in the seconde one?
No.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With