-
Notifications
You must be signed in to change notification settings - Fork 6
MOBILE-114: Add public API unregisterInAppCallback #706
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -17,6 +17,8 @@ import cloud.mindbox.common.MindboxCommon | |||||||||||||||
| import cloud.mindbox.mobile_sdk.Mindbox.disposeDeviceUuidSubscription | ||||||||||||||||
| 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 | ||||||||||||||||
| import cloud.mindbox.mobile_sdk.di.MindboxDI | ||||||||||||||||
| import cloud.mindbox.mobile_sdk.di.mindboxInject | ||||||||||||||||
| import cloud.mindbox.mobile_sdk.inapp.data.managers.SessionStorageManager | ||||||||||||||||
|
|
@@ -735,18 +737,72 @@ public object Mindbox : MindboxLog { | |||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| /** | ||||||||||||||||
| * Method to register callback for InApp Message | ||||||||||||||||
| * Registers a callback for InApp messages. | ||||||||||||||||
| * | ||||||||||||||||
| * Call this method after you call [Mindbox.init] | ||||||||||||||||
| * Call this method after [Mindbox.init]. The SDK holds a **strong reference** to | ||||||||||||||||
| * [inAppCallback], so the callback persists until explicitly replaced or removed via | ||||||||||||||||
| * [unregisterInAppCallback]. | ||||||||||||||||
| * | ||||||||||||||||
| * @param inAppCallback used to provide required callback implementation | ||||||||||||||||
| * Calling this method again replaces the previously registered callback. | ||||||||||||||||
| * | ||||||||||||||||
| * **Application-level callback (recommended):** | ||||||||||||||||
| * Register once in `Application.onCreate` with a callback that does not reference any | ||||||||||||||||
| * Activity. No cleanup needed. | ||||||||||||||||
| * ```kotlin | ||||||||||||||||
| * class MyApp : Application() { | ||||||||||||||||
| * override fun onCreate() { | ||||||||||||||||
| * super.onCreate() | ||||||||||||||||
| * Mindbox.init(...) | ||||||||||||||||
| * Mindbox.registerInAppCallback(MyGlobalInAppCallback()) | ||||||||||||||||
| * } | ||||||||||||||||
| * } | ||||||||||||||||
| * ``` | ||||||||||||||||
| * | ||||||||||||||||
| * **Per-screen callback:** | ||||||||||||||||
| * If different screens require different callback behavior and the callback captures an | ||||||||||||||||
| * Activity reference, use `onResume`/`onPause` — **not** `onCreate`/`onDestroy`. | ||||||||||||||||
| * Android guarantees that `onPause` of the current Activity is called before `onResume` | ||||||||||||||||
| * of the next, so callbacks never overlap and the Activity reference is always cleared | ||||||||||||||||
| * before the Activity can be garbage-collected. | ||||||||||||||||
|
Comment on lines
+765
to
+766
|
||||||||||||||||
| * 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. |
Copilot
AI
Apr 16, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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).