urbanairship / android-library

Urban Airship Android SDK
Other
109 stars 123 forks source link

We instantiate the listener but it seems that it is not being listened #213

Closed silviamirandastorm closed 1 year ago

silviamirandastorm commented 2 years ago

Hi guys, We have a problem in android implementation (lib version 16.6.1) We instantiate the listener but it seems that it is not being listened

example of adding listener ->> MessageCenter.shared().inbox.addListener(inboxListener)



Part of previous code for context



private val inboxListener = InboxListener { unreadMessages { ……. } } ...

fun unreadMessages(callback: (unread: Int) -> Unit) { CoroutineScope(Dispatchers.Main).launch { val unreadCount = MessageCenter.shared().inbox.unreadCount callback.invoke(unreadCount) } }

…



I can only fetch the unread messages by calling directly —>> unreadMessages { countUnreadMessages-> ….. }

Something else must be done to addListener???

rlepinski commented 2 years ago

Could you provide the full listener, its hard to tell what you are doing. The inbox listener only is called when the inbox message list is updated. It has no unreadMessage method.

rlepinski commented 2 years ago

Are you still having issue with this?

tarekatevenly commented 1 year ago

It doesn't work for me too. I tried with your own android repository and the listener in MainActivity doesn't work. I also tried in my own project and it didn't work. I am using "16.5.1"

rlepinski commented 1 year ago

@tarekatevenly could you provide more details and a snippet of how you are using it?

tarekatevenly commented 1 year ago

` I used this code snippet

override fun onResume() {
    super.onResume()
    viewModel.load()
    MessageCenter.shared().inbox.addListener(airshipListener)
}

override fun onStop() {
    MessageCenter.shared().inbox.removeListener(airshipListener)
    super.onStop()
}

private val airshipListener = InboxListener {
    setMessageCenterIndicator()
}

`

rlepinski commented 1 year ago

You probably want to add that listener during airship onReady instead of ti being tied to your activity. That way you can deeplink into the right place even if its not setup right.