当前位置:   article > 正文

安卓Service com.example.service_app.AdapterService has leaked ServiceConnection 解决方案_service com.zj.play_side.service.localservice has

service com.zj.play_side.service.localservice has leaked serviceconnection c
  1. E/ActivityThread: Service com.example.service_app.AdapterService has leaked ServiceConnection com.example.service_app.AdapterService$AdapterBinder$1@c11115 that was originally bound here
  2. android.app.ServiceConnectionLeaked: Service com.example.service_app.AdapterService has leaked ServiceConnection com.example.service_app.AdapterService$AdapterBinder$1@c11115 that was originally bound here
  3. at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:1610)
  4. at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:1502)
  5. at android.app.ContextImpl.bindServiceCommon(ContextImpl.java:1659)
  6. at android.app.ContextImpl.bindService(ContextImpl.java:1612)
  7. at android.content.ContextWrapper.bindService(ContextWrapper.java:698)
  8. at com.example.service_app.AdapterService$AdapterBinder.AccordApkNameAndFuncCallApkFunction(AdapterService.java:78)
  9. at com.example.service_app.IDapterAidlInterface$Stub.onTransact(IDapterAidlInterface.java:104)
  10. at android.os.Binder.execTransact(Binder.java:731)
  11. D/EGL_emulation: eglMakeCurrent: 0xe5d04360: ver 2 0 (tinfo 0xe5d036b0)

错误如上,项目背景app1通过AIDL调用app2的方法,此时调到的是app2服务里的方法,然后在app2服务里又会去请求app3里面的服务调用bindService(intent,conn,BIND_AUTO_CREATE);出现以上错误,因为我在app2里面的Activity里面也调用了bindService(intent,conn,BIND_AUTO_CREATE);因此出现以上错误,网上很多解决方案是 

  1. protected void onDestroy() {
  2. // TODO 自动生成的方法存根
  3. super.onDestroy();
  4. unbindService(conn);
  5. }

其实这是行不通的,因为这是Activity退出时才执行的接触绑定,我们可以手动接触绑定,在Activity调用bindService(intent,conn,BIND_AUTO_CREATE)的出发事件的最后(使用完bind)调用unbindService(conn);

即可解决以上错误

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/250943
推荐阅读
相关标签
  

闽ICP备14008679号