解决百度地图使用出现的has leaked ServiceConnection com.baidu.location.b@4aa5a810 that was originally bound here
生活随笔
收集整理的這篇文章主要介紹了
解决百度地图使用出现的has leaked ServiceConnection com.baidu.location.b@4aa5a810 that was originally bound here
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
使用百度地圖時,可能會碰到has leaked ServiceConnection com.baidu.location.b@4aa5a810 that was originally bound here這類錯誤,原因可能是沒有配置Map定位權限和遠程鏈接機制,或者是初始化LocationClient出現錯誤,錯誤情況如下:
Activity cn.demo.MainActivity has leaked ServiceConnection com.baidu.location.b@4aa5a810 that was originally bound hereandroid.app.ServiceConnectionLeaked: Activity cn.demo.MainActivity has leaked ServiceConnection com.baidu.location.b@4aa5a810 that was originally bound here at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:979) at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:873)
解決方法:
在注冊清單(AndroidManifest.xml)文件,配置Map定位權限和遠程鏈接機制,修改locationClient的 初始化,上下文不能寫當前activity,要寫getApplicationContext,如下:
- 1、添加定位權限
- 2、添加service標簽(在<application></application>之間添加)
- 3、locationClient 初始化的時候上下文不能寫當前activity,要寫getApplicationContext
完成配置后,重新安裝啟動,問題解決。
總結
以上是生活随笔為你收集整理的解决百度地图使用出现的has leaked ServiceConnection com.baidu.location.b@4aa5a810 that was originally bound here的全部內容,希望文章能夠幫你解決所遇到的問題。