活动MainActivity已泄露最初绑定在此处的ServiceConnection azu @ 42be3310

时间:2016-06-03 15:06:48

标签: android

我无法摆脱此错误消息

  

E / ActivityThread:活动com.example.project.MainActivity已泄露   最初绑定在这里的ServiceConnection azu @ 42be3310                                                                         android.app.ServiceConnectionLeaked:Activity   com.example.project.MainActivity已泄露ServiceConnection   原来绑在这里的azu @ 42be3310                                                                             在android.app.LoadedApk $ ServiceDispatcher。(LoadedApk.java:979)                                                                             在android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:873)                                                                             在android.app.ContextImpl.bindServiceCommon(ContextImpl.java:1690)                                                                             在android.app.ContextImpl.bindService(ContextImpl.java:1673)                                                                             在android.content.ContextWrapper.bindService(ContextWrapper.java:517)                                                                             ate.a(:com.google.android.gms.DynamiteModulesA:127)                                                                             ate.a(:com.google.android.gms.DynamiteModulesA:144)                                                                             at pg.b(:com.google.android.gms.DynamiteModulesA:348)                                                                             at pg.a(:com.google.android.gms.DynamiteModulesA:190)                                                                             在il.a(:com.google.android.gms.DynamiteModulesA:5176)                                                                             at im.run(:com.google.android.gms.DynamiteModulesA:1042)                                                                             在   java.util.concurrent.Executors $ RunnableAdapter.call(Executors.java:422)                                                                             在java.util.concurrent.FutureTask.run(FutureTask.java:237)                                                                             在   java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)                                                                             在   java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:587)                                                                             在java.lang.Thread.run(Thread.java:841)

1 个答案:

答案 0 :(得分:3)

这通常是在解除活动时绑定服务的结果。之前我通过在Activity中保留一个布尔值来跟踪服务是否绑定来解决它。然后在onDestroy中检查服务是否仍然与布尔实例变量绑定,如果服务仍然绑定,则取消绑定服务。

我还在onResume中对服务进行初始绑定,同时检查以确保它已经与我的布尔实例变量绑定,以防万一