Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unbind external service android Paho MQTT ServiceConnectionLeaked error

What's the proper way to unbind an external service (located in another jar) file in Android?

I declare the service (located in org.eclipse.paho.android.service-1.0.2.jar) in the manifest file as:

<service android:name="org.eclipse.paho.android.service.MqttService" >
</service>

Service source here

And the service runs properly. However, on exiting the app I get a ServiceConnectionLeaked error and after doing some searching I found that I need to call unbindService(...); on the onDestroy() method of the activity.

Log:

24915-24915/com.testapp.testmqtt E/ActivityThread﹕ Activity com.testapp.testmqtt.MainActivity has leaked ServiceConnection org.eclipse.paho.android.service.MqttAndroidClient$MyServiceConnection@426c50d8 that was originally bound here
    android.app.ServiceConnectionLeaked: Activity com.testapp.testmqtt.MainActivity has leaked ServiceConnection org.eclipse.paho.android.service.MqttAndroidClient$MyServiceConnection@426c50d8 that was originally bound here

However, I do not have a ServiceConnection to pass to unbindService() since I'm not manually starting the service. Is there any way to obtain the ServiceConnection of that service and unbind it?

like image 757
ᴘᴀɴᴀʏɪᴏᴛɪs Avatar asked Jun 03 '15 15:06

ᴘᴀɴᴀʏɪᴏᴛɪs


1 Answers

I just put this code in onDestroy of activity

    client.unregisterResources();
    client.close();
like image 58
Alan Donizete Avatar answered Oct 16 '22 00:10

Alan Donizete