jstuardo
jstuardo

Reputation: 4383

How can I send a message from MainActivity to Xamarin.Forms.Application object?

I need to send a message to the App object which was subscribed.

That App object is of Xamarin.Forms.Application class..... from MainActivity, in .Android project, I need to send a message to it, something like:

global::Xamarin.Forms.MessagingCenter.Send(this.Application, "AddItem", new string[]{ info.Code.ToString(), info.Description });

In this case, this.Application is not of type Xamarin.Forms.Application, so it did not work.

How can I solve this? I have spent several hours trying to find the solution in search engines but no avail.

Regards

Jaime

Upvotes: 0

Views: 980

Answers (1)

Jason
Jason

Reputation: 89117

Send and Subscribe need to use the same types for <T1,T2>

MessagingCenter.Send<object,string[]>(this, "AddItem", new string[]{ info.Code.ToString(), info.Description });

MessagingCenter.Subscribe<object,string[]>(this,"AddItem", (sender, arg) => {
  // do stuff here
});

Upvotes: 1

Related Questions