【问题标题】:Service has leaked ServiceConnection that was originally bound here服务泄露了原本绑定在这里的ServiceConnection
【发布时间】:2015-07-08 15:00:52
【问题描述】:

我正在使用启动 IntentService 的 BraodCastReceiver。一切看起来都很好,但我收到了这个我不知道其来源的错误:

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)

这是我的 BrodcastReceiver 类:

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);
        }
    }
}

这是我的 IntentService 类:

public class MyIntentService extends IntentService {

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

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

【问题讨论】:

  • 您的 SDK 似乎有些问题。请检查它是否正在建立任何服务连接。

标签: android service broadcastreceiver intentservice


【解决方案1】:

错误消息基本上意味着某些组件创建了与Service 的绑定,并且在组件被销毁之前没有与服务解除绑定。

您需要提供有关应用结构的更多信息,以便更好地回答您的问题。我会做一些猜测,也许会给你一些关于要探索的东西的想法。

我猜你正在使用 Clover 的库,也许还有 Merchantech。或者可能 Clover 库使用 Merchantech 库。我也猜测orderItem 是 Clover 定义的类的实例,而不是你。

Android 运行时会在 onHandleIntent() 完成后销毁 IntentService,并且没有更多 Intent 请求排队。您可以通过将 onDestroy() 方法添加到您的 MyIntentService 来确认这一点,并使用 Log 命令显示何时调用它。这意味着在您为 onHandleIntent() 发布的代码中,您的 IntentService 将在对 addLineItem() 的调用完成后不久被销毁。

堆栈跟踪表明调用orderItem.addLineItem() 触发的处理导致绑定到另一个服务。在某个地方,该绑定没有得到适当的管理——也许在应该的时候没有解除绑定。当您的组件(服务或活动)被销毁时,Clover 子系统是否希望您“关闭”它或“释放”资源?

【讨论】:

  • 据我所知,没有。但我会检查的。
【解决方案2】:

已解决

问题是由于 Clover SDK 造成的。他们没有解除绑定在 com.clover.sdk.v3.order.OrderConnector 类中某处的服务。所以这个问题和上面的代码sn-p无关。

【讨论】:

  • 应用程序并没有因为那个错误而崩溃,所以我保持原样。也许,Clover SDK 的所有者已经解决了这个问题。我没有检查他们是否这样做。希望我有所帮助
  • 我也有同样的问题,我找不到解决办法,让我检查一下天气更新到最新的 clover sdk 会解决这个问题吗?
  • @HiddenDroid 你找到解决办法了吗?
猜你喜欢
  • 1970-01-01
  • 2013-11-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-11-24
  • 1970-01-01
  • 2010-12-31
相关资源
最近更新 更多