Repository navigation
[SDK-791] Display in-app messages on the main thread when showMessage is called off it - #1102
Merged
Merged
Conversation
… is called off it Since 3.9.0 the Dialog renderer registers a LifecycleRegistry observer, which throws off the main thread. Post the display to the main looper, matching the iOS SDK. Main-thread callers are unchanged.
jferrao-itrbl
approved these changes
Oct 8, 2026
franco-zalamena-iterable
approved these changes
Oct 9, 2026
franco-zalamena-iterable
left a comment
Contributor
There was a problem hiding this comment.
I have one last "anti-flakiness" suggestion in a separate branch, will send you to you, for now there are only small suggestions
…ppManager.java Co-authored-by: Franco Zalamena <franco.zalamena@iterable.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📝 Summary
IterableInAppManager.showMessageis now safe to call from any thread: off the main thread it posts the display to the main looper.🎟️ Jira Ticket: SDK-791
📖 Description
Root cause behind SDK-789 (HelloFresh, RN 3.2.0 on native 3.10.1).
showMessagecalledIterableInAppDisplayer.showMessageon the caller thread. Since 3.9.0 (SDK-100), a host activity that is not aFragmentActivitytakes the Dialog path, andIterableInAppDialogNotification.createInstancecallsLifecycleRegistry.addObserver, which throwsIllegalStateException: Method addObserver must be called on the main thread. Before 3.9.0 that host was a silent no-op, and the Fragment path only posts throughFragmentTransaction.commit(), which is why calling from a background thread was latent for years.iOS already guarantees this:
InAppManager.show(message:consume:callback:)always dispatches to main ("This is public, so make sure we call from Main Thread").Change:
showMessageoverload (all public overloads andprocessMessagesfunnel into it) posts itself to the main looper when called off it, using the samenew Handler(Looper.getMainLooper()).postpattern asnotifyOnChange.setReadandmarkForDeletionstill run synchronously.The React Native bridge also hops in react-native-sdk#918 so RN 3.2.1 is fixed without waiting on this release. This PR protects native and Flutter callers.
🧪 How to test?
New
IterableInAppManagerThreadingTest(Robolectric, realComponentActivityhost, real displayer):showMessagefrom a backgroundHandlerThread(same shape as the RN native-modules thread) does not throw, does not display until the main looper runs, then displays the Dialog.showMessagefrom the main thread displays synchronously.With the hop removed, the background test fails with the production exception:
IllegalStateException: Method addObserver must be called on the main thread.Local results:
IterableInAppManagerTest,IterableInAppManagerSyncTest,IterableInAppDialogNotificationTest,IterableInAppHTMLNotificationTest, new threading test): 90 tests, 0 failures, 3 pre-existing@Ignore.:iterableapi:testDebugUnitTest: 793 tests, 1 failure inIterableAsyncInitializationTest.testOperationQueuing_LargeNumberOfOperations. That test does not touch the in-app manager and passes 3/3 in isolation on this branch and onmaster; it is a pre-existing flake under full-suite load (5 s init wait).checkstylepasses.🧾 Changelog
Added under
[Unreleased] > Fixed.📚 Docs PR if applicable
No public docs describe
showMessagethreading today; the Javadoc now does.