Skip to content

Fix Android crash from reusing a completed Result in the inbox listener - #11

Open
fa0311 wants to merge 1 commit into
salesforce-marketingcloud:mainfrom
fa0311:fix/android-inbox-listener
Open

Fix Android crash from reusing a completed Result in the inbox listener#11
fa0311 wants to merge 1 commit into
salesforce-marketingcloud:mainfrom
fa0311:fix/android-inbox-listener

Conversation

@fa0311

@fa0311 fa0311 commented Jul 19, 2026

Copy link
Copy Markdown

The Android inbox response listener keeps the MethodChannel.Result from the original registration call and invokes result.error(...) on later inbox responses. A Result can only be completed once, so this crashes with IllegalStateException: Reply already submitted. The listener also calls channel.invokeMethod directly from the SDK callback thread (channel methods are @UiThread), and nothing unregisters it on engine detach.

Now the registration result is completed exactly once and later errors are just logged, channel calls are posted to the main looper, double registration is guarded, and onDetachedFromEngine unregisters the listener.

…t channel calls to main thread

The inbox response listener captured the MethodChannel.Result from the
original registerInboxResponseListener call and invoked result.error()
on every later inbox response. Since that Result was already completed
at registration time, any subsequent call threw
IllegalStateException("Reply already submitted") and crashed the app.
The registration Result is now completed exactly once, and listener
errors are logged instead.

The listener also called channel.invokeMethod() directly from the
MarketingCloud SDK's callback thread. MethodChannel methods are
@UiThread-only and throw a RuntimeException on debug builds when called
from a background thread. Channel invocations are now posted to the
main thread via a Handler backed by the main looper.

Finally, the listener was never unregistered when the plugin detached
from the engine, leaking it, and repeated registration calls could
stack listeners. onDetachedFromEngine now unregisters the active
listener, and registration is a no-op when a listener is already
active, so at most one listener is ever registered.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants