MOBILE-114: Add public API unregisterInAppCallback#706
MOBILE-114: Add public API unregisterInAppCallback#706
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a new public API to remove a previously registered InApp callback and revert to the SDK’s default InApp handling.
Changes:
- Introduces
unregisterInAppCallback()in the publicMindboxAPI with accompanying KDoc. - Plumbs the new API through
InAppMessageManager/InAppMessageViewDisplayerand restores a stored default callback in the displayer implementation. - Adds unit tests verifying callback registration/unregistration behavior in
InAppMessageViewDisplayerImpl.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| sdk/src/main/java/cloud/mindbox/mobile_sdk/Mindbox.kt | Adds public unregisterInAppCallback() and expands documentation for callback lifecycle. |
| sdk/src/main/java/cloud/mindbox/mobile_sdk/inapp/presentation/InAppMessageManager.kt | Adds unregisterInAppCallback() to manager interface. |
| sdk/src/main/java/cloud/mindbox/mobile_sdk/inapp/presentation/InAppMessageManagerImpl.kt | Implements unregisterInAppCallback() and switches wrappers to loggingRunCatching. |
| sdk/src/main/java/cloud/mindbox/mobile_sdk/inapp/presentation/InAppMessageViewDisplayer.kt | Adds unregisterInAppCallback() to displayer interface. |
| sdk/src/main/java/cloud/mindbox/mobile_sdk/inapp/presentation/InAppMessageViewDisplayerImpl.kt | Stores a defaultCallback and resets to it on unregister. |
| sdk/src/test/java/cloud/mindbox/mobile_sdk/inapp/presentation/InAppMessageViewDisplayerImplTest.kt | Adds tests covering default, register, unregister, and repeated register scenarios. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| import cloud.mindbox.mobile_sdk.Mindbox.disposePushTokenSubscription | ||
| import cloud.mindbox.mobile_sdk.Mindbox.handleRemoteMessage | ||
| import cloud.mindbox.mobile_sdk.Mindbox.registerInAppCallback | ||
| import cloud.mindbox.mobile_sdk.Mindbox.unregisterInAppCallback |
There was a problem hiding this comment.
These two imports appear to be unused in code (only referenced in KDoc, and the KDoc links already resolve without importing members from the same object). With ktlint enabled in this repo (modulesCommon.gradle applies org.jlleitschuh.gradle.ktlint), unused imports will fail the lint task. Please remove these imports (or switch KDoc links to fully-qualified names if you intended to rely on imports for link resolution).
| import cloud.mindbox.mobile_sdk.Mindbox.unregisterInAppCallback |
| * of the next, so callbacks never overlap and the Activity reference is always cleared | ||
| * before the Activity can be garbage-collected. |
There was a problem hiding this comment.
The KDoc here claims that unregistering in onPause ensures the Activity reference is cleared before the Activity can be garbage-collected. In the current implementation, the callback is captured into InAppCallbackWrapper(callback: InAppCallback) when an in-app is shown (see InAppCallbackWrapper.kt), so any currently displayed/paused in-app can still hold the old callback (and its Activity reference) even after unregisterInAppCallback() is called. Please adjust the documentation to reflect that unregistering affects only future in-apps (or change the callback wiring so the wrapper delegates to the current callback rather than capturing a snapshot).
| * of the next, so callbacks never overlap and the Activity reference is always cleared | |
| * before the Activity can be garbage-collected. | |
| * of the next, so callback registrations for future in-apps do not overlap. | |
| * Note: `unregisterInAppCallback()` affects only future in-apps. An in-app that is | |
| * already being shown may still hold the callback instance that was captured when it | |
| * was displayed, so unregistering in `onPause` does not retroactively clear that | |
| * reference. |
| * **When to call:** | ||
| * Only needed for per-screen callbacks registered in `onResume`. Call in the corresponding | ||
| * `onPause` to release the Activity reference and restore default behavior while another | ||
| * screen is in the foreground. |
There was a problem hiding this comment.
This section says calling unregisterInAppCallback() in onPause will "release the Activity reference". Given the callback is copied into InAppCallbackWrapper at render time, an active/paused in-app may still retain the previous callback instance until it is dismissed/closed. Please either clarify this in the KDoc (e.g., recommend dismissing current in-app before unregistering if the callback captures an Activity) or update the implementation so active holders stop referencing the old callback after unregistration.
https://tracker.yandex.ru/MOBILE-114