![](/img/trans.png)
[英]How can I bring the PAHO/Eclipse MQTT Android Service into an Android Studio Project
[英]Unbind external service android Paho MQTT ServiceConnectionLeaked error
在Android中取消綁定外部服務(位於另一個jar)文件的正確方法是什么?
我將清單文件中的服務(位於org.eclipse.paho.android.service-1.0.2.jar
)聲明為:
<service android:name="org.eclipse.paho.android.service.MqttService" >
</service>
服務來源在這里
服務運行正常。 但是,在退出應用程序時,我收到ServiceConnectionLeaked
錯誤,在進行一些搜索后,我發現需要調用unbindService(...);
在活動的onDestroy()
方法上。
日志:
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
但是,我沒有將ServiceConnection
傳遞給unbindService()
因為我沒有手動啟動該服務。 有沒有辦法獲得該ServiceConnection
並解除綁定?
我只是將此代碼放在onDestroy活動中
client.unregisterResources();
client.close();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.