[Solved] Service has leaked ServiceConnection that was originally bound here

I am using a BraodCastReceiver that starts an IntentService. Everythings look working good, but I get this error which I don’t know its source:

android.app.ServiceConnectionLeaked: Service     com.merchantech.app.smartdiscount.MyIntentService has leaked ServiceConnection  [email protected]535008f4 that was originally bound here
        at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
        at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
        at android.app.ContextImpl.bindService(ContextImpl.java:1426)
        at android.app.ContextImpl.bindService(ContextImpl.java:1415)
        at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
        at com.clover.sdk.v1.ServiceConnector.connect(ServiceConnector.java:119)
        at com.clover.sdk.v1.ServiceConnector.waitForConnection(ServiceConnector.java:148)
        at com.clover.sdk.v1.ServiceConnector.execute(ServiceConnector.java:209)
        at com.clover.sdk.v3.order.OrderConnector.getOrder(OrderConnector.java:153)
        at com.merchantech.app.smartdiscount.MyIntentService.onHandleIntent(MyIntentService.java:41)
        at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:137)
        at android.os.HandlerThread.run(HandlerThread.java:60)

Here’s my BrodcastReceiver class:

public class MyReceiver extends BroadcastReceiver {

    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if (action.equals("com.test.intent.action.LINE_ITEM_ADDED")) {
            Intent i = new Intent(context, MyIntentService.class);

And here’s my IntentService class:

public class MyIntentService extends IntentService {

    public MyIntentService() {

    protected void onHandleIntent(Intent intent) {
        orderItem.addLineItem(orderId, lineItemId, var);

Solution #1:

The error message basically means that some component created a binding to a Service and did not unbind from the service before the component was destroyed.

You will need to provide more information about your app’s structure to get a better answer to your question. I’ll make some guesses, and maybe give you some ideas about things to explore.

I’m guessing that you are using a library from Clover and maybe also Merchantech. Or maybe the Clover library uses a Merchantech library. I’m also guessing that orderItem is an instance of a class defined by Clover, not you.

The Android runtime destroys an IntentService after onHandleIntent() completes and there are no more Intent requests queued. You can confirm this by adding the onDestroy() method to your MyIntentService with a Log command to show when it is called. That means that in the code you posted for onHandleIntent(), your IntentService will be destroyed soon after the call to addLineItem() completes.

The stack trace suggests that the processing triggered by the call to orderItem.addLineItem() causes a binding to another service. Somewhere, that binding is not being managed properly–maybe not unbound when it should be. Is there something the Clover subsystem expects you do to “close” it or “release” resources when your component (Service or Activity) is being destroyed?

Respondent: Bob Snyder

Solution #2:


The problem is due to the Clover SDK. They have not unbind a service that was bounded somewhere in the com.clover.sdk.v3.order.OrderConnector Class. So the problem is not relevant to the code snippet above.

Respondent: HiddenDroid

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Leave a Reply

Your email address will not be published.