strada-android
strada-android copied to clipboard
BridgeComponent onReceive invoked twice
As the title says. The first time the component is initialised the onReceive method is invoked once as expected. Subsequent visits to any page where the component is used will see the onReceive
method invoked twice. The issue became apparent because I was having menu items added twice and I thought it was something else. I tested this with the main Turbo demo Android application and found the same behaviour.
I am currently using this workaround:
open class LinkTo (
name: String,
private val delegate: BridgeDelegate<NavDestination>,
) : BridgeComponent<NavDestination>(name, delegate) {
private var isNew = false
override fun onReceive(message: Message) {
if(!isNew) {
when (message.event) {
"connect" -> handleConnectEvent(message)
else -> Log.w("TurboDemo", "Unknown event for message: $message")
}
isNew = true
}
}