tags:

views:

267

answers:

2

Hi!

I have multiple activities and one service.. In MainActivity I successfully connect to service (using a class what 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): Activity com.app.liviu.simpleMusicPlayer.PlaylistActivity has leaked ServiceConnection com.app.liviu.simpleMusicPlayer.PlaylistActivity$CounterServiceConnection@43713c90 that was originally bound here 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.

It Is possible to connect to service in an other way: something like to make static my CounterServiceConnection object in MainActivity and use it in the second one?

Thank you!

A: 

You can bind it from a separate thread as long as you install a looper in that thread

Will
+1  A: 

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.

CommonsWare
this is saying what the error is, not how to solve the problem
Will