I am writing a service for my Android app and I am trying to understand how the binding mechanism works. If I bind my service in the onCreate of an activity but I don't unbind it in onStop or onDestroy, I get the error :
android.app.ServiceConnectionLeaked: Service com.google.ipc.invalidation.ticl.android.AndroidInvalidationService has leaked ServiceConnection com.googl
e.ipc.invalidation.external.client.android.service.ServiceBinder$1@4177f8f8 that was originally bound here
So my question is : what is the problem exactly with leaking a connection, what am I preventing by unbinding my service ?
This issue occurs when the Android OS destroys your Activity
while a ServiceConnection
is still bound to a running Service. To prevent this, you need to unbind the service before the Activity
is destroyed.