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?
I just put this code in onDestroy of activity
client.unregisterResources();
client.close();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With