首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Android向PCL传递数据未收到MessagingCenter消息

Android向PCL传递数据未收到MessagingCenter消息
EN

Stack Overflow用户
提问于 2017-08-18 00:49:18
回答 1查看 1.2K关注 0票数 2

我正在尝试将数据从MainActivity发送回PCL视图。当我发送一条没有数据的消息时,它会接收它。但是,当我试图用它传递回一个字符串时,代码永远也达不到。

在MainActivity中:

代码语言:javascript
复制
if(data != null)
            {

                MessagingCenter.Send<object, string>(this, data, "MapIntentReceived");
                MessagingCenter.Send<object>(this, "MapIntentReceived");

            }

在PCL中:

代码语言:javascript
复制
            MessagingCenter.Subscribe<object, string>(this, "MapIntentReceived",
                async (sender, roomString) =>
                {   //his code is not reached
                    await SearchForRooms(roomString);
                });

            MessagingCenter.Subscribe<object>(this, "MapIntentReceived",
                async (sender) =>
                {   //this code is reached
                    await SearchForRooms("blah");
                });

谢谢你的帮助。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-08-18 00:58:29

若要发送带有参数的消息,请在send方法调用中包括Type泛型参数和参数的值。

代码语言:javascript
复制
MessagingCenter.Send<MainPage, string> (this, "MapIntentReceived", data);

若要在消息中传递参数,请在订阅泛型参数和操作签名中指定参数类型。

代码语言:javascript
复制
MessagingCenter.Subscribe<MainPage, string> (this, "MapIntentReceived", (sender, arg) => {
    await SearchForRooms(arg);
});

对于取消订阅

代码语言:javascript
复制
MessagingCenter.Unsubscribe<MainPage, string> (this, "MapIntentReceived");
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45740892

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档