gpt4 book ai didi

java - 解绑外部服务android Paho MQTT ServiceConnectionLeaked报错

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:52:55 24 4
gpt4 key购买 nike

在 Android 中解除绑定(bind)外部服务(位于另一个 jar 中)文件的正确方法是什么?

我在 list 文件中将服务(位于 org.eclipse.paho.android.service-1.0.2.jar)声明为:

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

服务来源here

服务正常运行。但是,在退出应用程序时,我收到了 ServiceConnectionLeaked 错误,在进行了一些搜索后,我发现我需要调用 onDestroy 上的 unbindService(...); () Activity 的方法。

日志:

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

但是,我没有要传递给 unbindService()ServiceConnection,因为我没有手动启动该服务。有没有办法获取该服务的ServiceConnection并解除绑定(bind)?

最佳答案

我只是把这段代码放在 Activity 的onDestroy中

    client.unregisterResources();
client.close();

关于java - 解绑外部服务android Paho MQTT ServiceConnectionLeaked报错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30624834/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com