7

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  com.clover.sdk.v3.order.OrderConnector@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 {

    @Override
    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);
            context.startService(i);
        }
    }
}

And here's my IntentService class:

public class MyIntentService extends IntentService {

    public MyIntentService() {
        super("MyIntentService");
    }

    @Override
    protected void onHandleIntent(Intent intent) {
        orderItem.addLineItem(orderId, lineItemId, var);
    }
}
msayag
  • 8,407
  • 4
  • 30
  • 29
HiddenDroid
  • 1,440
  • 4
  • 14
  • 27
  • It looks like some issue with your SDK. Please check whether it is making any service connection. – siva Jul 08 '15 at 15:58

2 Answers2

9

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?

Bob Snyder
  • 37,759
  • 6
  • 111
  • 158
2

Solved:

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.

HiddenDroid
  • 1,440
  • 4
  • 14
  • 27
  • The app wasn't crashing because of that error, so I left it as it was. Maybe, owners of Clover SDK have fixed this problem. I didn't check if they did or not. Hope I helped – HiddenDroid Mar 13 '16 at 12:33
  • I also have the same issue & i could not find a solution to it, let me check and update weather updating to latest clover sdk will fix this ? – Rasheed Aug 07 '19 at 04:42
  • 1
    @HiddenDroid did you find any solution to it ? – Rasheed Aug 07 '19 at 04:42
  • @HiddenDroid Still throwing same error with v293?, Any work around ? – Parag Chauhan Apr 14 '23 at 08:56