Reputation: 2010
I can't get rid of this error message
E/ActivityThread: Activity com.example.project.MainActivity has leaked ServiceConnection azu@42be3310 that was originally bound here android.app.ServiceConnectionLeaked: Activity com.example.project.MainActivity has leaked ServiceConnection azu@42be3310 that was originally bound here at android.app.LoadedApk$ServiceDispatcher.(LoadedApk.java:979) at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:873) at android.app.ContextImpl.bindServiceCommon(ContextImpl.java:1690) at android.app.ContextImpl.bindService(ContextImpl.java:1673) at android.content.ContextWrapper.bindService(ContextWrapper.java:517) at bye.a(:com.google.android.gms.DynamiteModulesA:127) at bye.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) at il.a(:com.google.android.gms.DynamiteModulesA:5176) at im.run(:com.google.android.gms.DynamiteModulesA:1042) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422) at java.util.concurrent.FutureTask.run(FutureTask.java:237) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) at java.lang.Thread.run(Thread.java:841)
Upvotes: 2
Views: 3757
Reputation: 1370
This is usually a result of a Service being bound when an Activity is dismissed. I've solved it before by keeping a boolean value in the Activity that keeps track of whether or not the Service is bound. Then in onDestroy
check if the Service is still bound with the boolean instance variable and unbind the Service if it is still bound.
I also do my initial binding of the Service in onResume
while checking to make sure it isn't already bound with my boolean instance variable just in case
Upvotes: 3