Service leaked ServiceConnection which was originally linked here

I am using BraodCastReceiver which launches IntentService. Everything looks 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 is my IntentService class:

public class MyIntentService extends IntentService {

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

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

      

+3


source to share


2 answers


solved



The problem is related to the Clover SDK. They do not unbind a service that was constrained somewhere in the com.clover.sdk.v3.order.OrderConnector class. Thus, the problem does not apply to the code snippet above.

+2


source


The error message basically means that some component created a binding to Service

and did not unbind the service before the component was destroyed.

You will need to provide additional information about the structure of your application in order to get the best answer to your question. I'll make some guesses and maybe give you some ideas on what to research.

I am assuming you are using a library from Clover and perhaps also Merchantech. Or perhaps the Clover library uses the Merchantech library. I also assume that orderItem

is an instance of a class defined by Clover and not you.



The Android runtime kills IntentService

after onHandleIntent()

and there are no more requests for the Intent. You can confirm this by adding a method onDestroy()

to yours MyIntentService

with the Log command to show when it is called. This means that in the code you posted for onHandleIntent()

, your IntentService will be destroyed shortly after the call completes addLineItem()

.

The stack trace suggests that the processing orderItem.addLineItem()

invoked by the call invokes a binding to another service. Somewhere this binding is not properly managed - perhaps not untied when it should be. Is there something that the Clover subsystem expects you to "close" or "release" when your component (service or activity) is destroyed?

+7


source







All Articles