InboxEventObserver
Implementation of AepInboxEventObserver for handling inbox-level events and delegating item-level events to content card observers.
- Handles inbox events: Automatically tracks inbox display events and sends them to Adobe Journey Optimizer
- Delegates item events: Forwards content card events (display, interact, dismiss) to the provided observer
- Prevents duplicates: Avoids sending redundant inbox display tracking for the same successful load (handled inside the Messaging SDK)
Constructor
Copied to your clipboardInboxEventObserver(provider: MessagingInboxProvider,itemEventObserver: AepUIEventObserver? = null)
Parameters
| Parameter | Type | Description |
|---|---|---|
provider | The provider that owns the inbox state. The observer will call provider.updateInboxState() to update the inbox state after handling events. | |
itemEventObserver | An optional observer that handles item-level events. When null, a default ContentCardEventObserver with null callback will be used. |
Methods
onEvent
Inherited from AepUIEventObserver. Delegates item-level events to all provided observers.
Usage
Basic Usage (No Custom Event Handling)
Create the observer in your ViewModel and pass it to AepInbox:
Copied to your clipboardimport androidx.lifecycle.ViewModelimport androidx.lifecycle.viewModelScopeimport com.adobe.marketing.mobile.messaging.InboxEventObserverimport com.adobe.marketing.mobile.messaging.MessagingInboxProviderimport com.adobe.marketing.mobile.messaging.Surfaceimport kotlinx.coroutines.flow.SharingStartedimport kotlinx.coroutines.flow.stateInclass InboxViewModel : ViewModel() {val inboxProvider = MessagingInboxProvider(Surface("inbox"))val observer = InboxEventObserver(inboxProvider)val inboxUIState = inboxProvider.getInboxUI().stateIn(scope = viewModelScope,started = SharingStarted.WhileSubscribed(5000),initialValue = InboxUIState.Loading)}@Composablefun InboxScreen(viewModel: InboxViewModel) {val inboxUIState by viewModel.inboxUIState.collectAsStateWithLifecycle()AepInbox(uiState = inboxUIState,observer = viewModel.observer)}
With Content Card Event Handling
To handle content card events (display, interact, dismiss), pass a ContentCardEventObserver to the InboxEventObserver:
Copied to your clipboardimport com.adobe.marketing.mobile.aepcomposeui.AepUIimport com.adobe.marketing.mobile.messaging.ContentCardEventObserverimport com.adobe.marketing.mobile.messaging.ContentCardUIEventListenerimport com.adobe.marketing.mobile.messaging.InboxEventObserverclass InboxViewModel : ViewModel() {private val cardCallback = object : ContentCardUIEventListener {override fun onDisplay(aepUI: AepUI<*, *>) {Log.d("Inbox", "Card displayed: ${aepUI.getTemplate().id}")}override fun onInteract(aepUI: AepUI<*, *>,interactionId: String?,actionUrl: String?): Boolean {Log.d("Inbox", "Card interacted: $interactionId")// Return true if you handled the action URLreturn false}override fun onDismiss(aepUI: AepUI<*, *>) {Log.d("Inbox", "Card dismissed: ${aepUI.getTemplate().id}")}}val inboxProvider = MessagingInboxProvider(Surface("inbox"))val observer = InboxEventObserver(inboxProvider,ContentCardEventObserver(cardCallback))val inboxUIState = inboxProvider.getInboxUI().stateIn(scope = viewModelScope,started = SharingStarted.WhileSubscribed(5000),initialValue = InboxUIState.Loading)}
Best Practices
Create in ViewModel: Keep one
MessagingInboxProviderand oneInboxEventObserver(provider, …)in the sameViewModelso state and event handling stay aligned across configuration changes.Avoid Heavy Work: Event handlers run on the main thread. Keep them lightweight and dispatch heavy work to background threads.
Single Observer Instance: Use one
InboxEventObserverper inbox surface and pass it toAepInbox; reuse the same provider instance forgetInboxUI()and for the observer constructor argument.
