Description
I've encountered a leak problem. I was using a simulator without Chrome installed. On a Chrome installed simulator the leak won't happen.
This leak was occurred when I hit the back button and while the MainActivity turned into background.
And when I dig a little deeper into the problem I found that the mBrowserPackage
in the BrowserHandler
was resolved to com.android.browser
and the return value of CustomTabsClient#bindCustomTabsService(...)
is false. So the connection is not retained in the BrowserHandler
and when BrowserHandler#unbind()
is called, nothing is unbind.
I've tried to retained the connection even when CustomTabsClient#bindCustomTabsService(...)
returns false. It seems solve the leak problem, but I'm not sure will there be any side effects.
07-06 10:12:45.442 3929-3929/net.openid.appauthdemo E/ActivityThread: Activity net.openid.appauthdemo.MainActivity has leaked ServiceConnection net.openid.appauth.BrowserHandler$1@2206f76 that was originally bound here
android.app.ServiceConnectionLeaked: Activity net.openid.appauthdemo.MainActivity has leaked ServiceConnection net.openid.appauth.BrowserHandler$1@2206f76 that was originally bound here
at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:1092)
at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:986)
at android.app.ContextImpl.bindServiceCommon(ContextImpl.java:1303)
at android.app.ContextImpl.bindService(ContextImpl.java:1286)
at android.content.ContextWrapper.bindService(ContextWrapper.java:604)
at android.support.customtabs.CustomTabsClient.bindCustomTabsService(CustomTabsClient.java:60)
at net.openid.appauth.BrowserHandler.bindCustomTabsService(BrowserHandler.java:86)
at net.openid.appauth.BrowserHandler.<init>(BrowserHandler.java:61)
at net.openid.appauth.AuthorizationService.<init>(AuthorizationService.java:101)
at net.openid.appauthdemo.MainActivity.onCreate(MainActivity.java:63)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)