question

vadzim avatar image
vadzim asked Kavin Kannan answered

"Activity ... has leaked ServiceConnection" exception on android

If I set my applicationId in gradle to something that does not start with com.clover I get "Activity has leaked ServiceConnection" when I try to do orderConnector.connect();

com.clover.abcdef works, com.abcdef does not.

How to reproduce:

  1. Take modifyorderbutton example from clover/android-examples repository
  2. Add this line to android module in app's build.gradle: defaultConfig { applicationId "com.abc" }
  3. Launch application, press the 'Add discount' button, you will see this exception in logs, and order will not be changed.

I can't attach full log as a file, so I will add short version here:

11-18 15:24:13.156 29977-29977/com.abc E/ActivityThread: Activity com.clover.example.modifyorder.app.AddDiscountActivity has leaked ServiceConnection com.clover.sdk.v3.order.OrderConnector@52801948 that was originally bound here

11-18 15:24:13.156 29977-29977/com.abc E/ActivityThread: android.app.ServiceConnectionLeaked: Activity com.clover.example.modifyorder.app.AddDiscountActivity has leaked ServiceConnection com.clover.sdk.v3.order.OrderConnector@52801948 that was originally bound here

...

com.clover.sdk.v1.ServiceConnector.connect(ServiceConnector.java:119) 11-18 15:24:13.156 29977-29977/com.abc E/ActivityThread: at com.clover.example.modifyorder.app.AddDiscountActivity$2.doInBackground(AddDiscountActivity.java:50)

10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Jacob Abrams avatar image
Jacob Abrams answered

I believe the leaked connection is a side effect of a security exception being thrown before the connection is closed. The example code would not leak if the connection was closed in a finallyclause which is a safer way to code this. Do you see anything else in the logs? 3rd party apps must register what permissions they require so the merchant can see it and approve it upon installation, please follow the steps in https://docs.clover.com/build/android... to setup permissions for your app. Apps that start with com.clover do not require this and will not have security a security exception, however only Clover is allowed to publish apps that start with com.clover.

10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Kavin Kannan avatar image
Kavin Kannan answered

In my case, activity was trying to be finished when there was an active order connection.

So you may check if you have finish(); call somewhere. If you do, I'de suggest you to disconnect orders connector before you call finish() in your activity.

10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Welcome to the
Clover Developer Community