1

MessagingCenter.Subscribe calling multile times but i called MessagingCenter.send only one time.how to resolve this issue.

I'm subscribe from model's constructor

 MessagingCenter.Subscribe<App, List<string>>(this, "hi", async (arg1, list) =>
        { //code });

calling send in android's renderer

Xamarin.Forms.MessagingCenter.Send<App, List<string>>((App)Xamarin.Forms.Application.Current, "hi", list);
Dev
  • 315
  • 2
  • 16
  • have you put unsubscribe in your OnDisappearing? and also try to put that subscribe in your OnAppearing rather than the constructor – Godya Aditya May 18 '21 at 08:03
  • 1
    One way to avoid multiple copies of `Subscribe`, is to call `Unsubscribe` with same parameters, immediately before you call Subscribe. This deletes any previous subscription. – ToolmakerSteve May 18 '21 at 19:43
  • Thanks ToolmakerSteve, that worked perfectly. You both should propose as answers and let people upvote the one they prefer. Thanks again! – drHodge Aug 31 '21 at 17:29

0 Answers0