This question is a follow-up / "second attempt" to a previous question of mine.
I am building a cross-platform mobile application using MvvmCross framework, and I would like to use the Messenger plugin to receive event notifications published from somewhere else in my code.
I have tried to add the subscription in the ctor
as follows:
public class MyViewModel : BaseViewModel, IMyViewModel
{
private MvxSubscriptionToken _showMsgToken;
public MyViewModel ()
{
_showMsgToken = MvxMessenger.Subscribe<ShowMsg>(message => onShowNavigation(), MvxReference.Weak);
}
private void onShowNavigation()
{
//Do Stuff
}
}
Now when I navigate to this ViewModel everything works and notifications are received.
However, when I navigate away and back to this ViewModel, I can see that the Subscription is adding another entry to the MvxMessenger
subscriptions property, resulting onShowAdsNavigation()
firing twice for each new event.
So, How can I subscribe to events in the ViewModel? Or maybe I need to find a way to Unsubscribe from events?