novoda / simple-chrome-custom-tabs

Easy integration of Chrome Custom Tabs into your project. Just connect it to your activity, and navigate to the external website styling your tab as you wish.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Causes RunTimeException

meierjan opened this issue · comments

Stacktrace:

Fatal Exception: java.lang.RuntimeException: Unable to pause activity {net.nextbike.serviceapp/net.nextbike.serviceapp.menu.view.MenuActivity}: java.lang.IllegalArgumentException: Service not registered: com.novoda.simplechromecustomtabs.connection.Binder$ServiceConnection@16dee566
       at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3693)
       at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3652)
       at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:3627)
       at android.app.ActivityThread.access$1100(ActivityThread.java:177)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1443)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:135)
       at android.app.ActivityThread.main(ActivityThread.java:5912)
       at java.lang.reflect.Method.invoke(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:372)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1405)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1200)
Caused by java.lang.IllegalArgumentException: Service not registered: com.novoda.simplechromecustomtabs.connection.Binder$ServiceConnection@16dee566
       at android.app.LoadedApk.forgetServiceDispatcher(LoadedApk.java:1094)
       at android.app.ContextImpl.unbindService(ContextImpl.java:2000)
       at android.content.ContextWrapper.unbindService(ContextWrapper.java:558)
       at com.novoda.simplechromecustomtabs.connection.Binder.unbindCustomTabsService(Binder.java:57)
       at com.novoda.simplechromecustomtabs.connection.SimpleChromeCustomTabsConnection.disconnectFrom(SimpleChromeCustomTabsConnection.java:67)
       at com.novoda.simplechromecustomtabs.SimpleChromeCustomTabs.disconnectFrom(SimpleChromeCustomTabs.java:123)
       at net.nextbike.serviceapp.base.BaseActivity.onPause(BaseActivity.java:84)
       at net.nextbike.serviceapp.base.LocationAwareActivity.onPause_aroundBody2(LocationAwareActivity.java:60)
       at net.nextbike.serviceapp.base.LocationAwareActivity$AjcClosure3.run(LocationAwareActivity.java:1)
       at org.aspectj.runtime.reflect.JoinPointImpl.proceed(JoinPointImpl.java:149)
       at hugo.weaving.internal.Hugo.logAndExecute(Hugo.java:39)
       at net.nextbike.serviceapp.base.LocationAwareActivity.onPause(LocationAwareActivity.java:57)
       at android.app.Activity.performPause(Activity.java:6343)
       at android.app.Instrumentation.callActivityOnPause(Instrumentation.java:1322)
       at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3679)
       at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3652)
       at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:3627)
       at android.app.ActivityThread.access$1100(ActivityThread.java:177)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1443)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:135)
       at android.app.ActivityThread.main(ActivityThread.java:5912)
       at java.lang.reflect.Method.invoke(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:372)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1405)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1200)

Statistics:
83 % Samsung
17 % Sony

75 % Android 5
25 % Android 4

The methods in BaseActivity are:

   @Override
    protected void onResume() {
        super.onResume();
        SimpleChromeCustomTabs.getInstance().connectTo(this);

    }

    @Override
    protected void onPause() {
        SimpleChromeCustomTabs.getInstance().disconnectFrom(this);
        super.onPause();
    }

Thank you for the report @meierjan , sounds like trying to disconnect from a service that was never connected? But apparently that shouldn't be the case given the piece of code you have shared.

I've never experimented something like that, need to investigate.

Is that happening all the time?
Are there any specific steps to reproduce the issue?
Can you tell me a device model where it is consistently reproducible?

That will facilitate debugging.

Hey,
I cant reproduce it. But I can see it in my metrics. The app is out for 10 days (deployed in 3 versions) and it happed 6 times across all versions for 3 (of maybe 10) users.

Just saying that we see the same now that we have deployed the app (never happened during testing).

Similar crashlytics report, like:

Fatal Exception: java.lang.RuntimeException: Unable to pause activity {package/package.SomeActivity}: java.lang.IllegalArgumentException: Service not registered: com.c.b.a.a$a@12e9f74f
       at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3874)
       at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3833)
       at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:3808)
       at android.app.ActivityThread.access$1100(ActivityThread.java:181)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1493)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:145)
       at android.app.ActivityThread.main(ActivityThread.java:6145)
       at java.lang.reflect.Method.invoke(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:372)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
Caused by java.lang.IllegalArgumentException: Service not registered: com.c.b.a.a$a@12e9f74f
       at android.app.LoadedApk.forgetServiceDispatcher(LoadedApk.java:1096)
       at android.app.ContextImpl.unbindService(ContextImpl.java:2188)
       at android.content.ContextWrapper.unbindService(ContextWrapper.java:571)
       at com.novoda.simplechromecustomtabs.connection.SimpleChromeCustomTabsConnection.com.novoda.simplechromecustomtabs.connection.Binder.unbindCustomTabsService(SimpleChromeCustomTabsConnection.java:3057)
       at com.novoda.simplechromecustomtabs.SimpleChromeCustomTabs.disconnectFrom(SimpleChromeCustomTabs.java:123)
       at package.SomeFragment.onPause(NowFragment.java:108)
       at android.support.v4.app.Fragment.performPause(Fragment.java:2123)
       at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1118)
       at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1248)
       at android.support.v4.app.FragmentManagerImpl.moveToState$2563266(FragmentManager.java:1230)
       at android.support.v4.app.FragmentActivity.android.support.v4.app.FragmentManagerImpl.dispatchPause(FragmentActivity.java:17056)

and

Fatal Exception: java.lang.RuntimeException: Unable to pause activity {package/package.SomeActivity}: java.lang.IllegalArgumentException: Service not registered: com.c.b.a.a$a@1d8f82a
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2518)
       at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:4077)
       at android.app.ActivityThread.-wrap15(ActivityThread.java)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1350)
       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(Method.java)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by java.lang.IllegalArgumentException: Service not registered: com.c.b.a.a$a@1d8f82a
       at android.app.LoadedApk.forgetServiceDispatcher(LoadedApk.java:1044)
       at android.app.ContextImpl.unbindService(ContextImpl.java:1337)
       at android.content.ContextWrapper.unbindService(ContextWrapper.java:616)
       at com.c.b.a.e.b(SimpleChromeCustomTabsConnection.java:3057)
       at com.c.b.a.b(SimpleChromeCustomTabs.java:123)
       at package.SomeFragment.onPause(SomeFragment.java:108)
       at android.support.v4.app.Fragment.performPause(Fragment.java:2123)
       at android.support.v4.app.o.a(FragmentManager.java:1118)
       at android.support.v4.app.o.a(FragmentManager.java:1248)
       at android.support.v4.app.o.b(FragmentManager.java:1230)
       at android.support.v4.app.j.onPause(FragmentActivity.java:17056)
       at package.d.onPause(SomeActivity.java:64)
       at android.app.Activity.performPause(Activity.java:6363)

All kinds of devices:

  • Nexus 5 - Android 6.0.1
  • Samsung Galaxy A3 - Android 5.0.2
  • Samsung Galaxy S4 mini - Android 4.4.4
  • Samsung Galaxy S3 - Android 4.3
  • OnePlus One - Android 5.1.1
  • ...

Hi @filipmaelbrancke @meierjan, and other guys interested on this issue.

I have just released 0.1.3-rc1 with the changes that, I believe, fixes this.

I believe that the issue is related to the fact that, somehow, the services was being unbinded with a different context from the one used for binding. There are two things done to mitigate the issue:

  1. Uses application Context for binding/unbinding.
  2. Defensive code to avoid crashing.

More details here: #18

Please let me know if this fixes your issues so I can promote this to something more than just a release candidate. Given there is no way to replicate this (tried stressing with monkey runner) your collaboration would be really valuable.

#22

Wrapping the .disconnectFrom with a isConnected check fixes this

Fixed