我无法真正遵循您的示例代码 - 它并没有真正解释:
- 你是如何创建 HomeView 的
- 它是如何将它的信使实例传递给它的。
- 是什么生成了 ApplicationError_Message 消息
- 您如何理解消息是否到达
作为快速测试,我在 InternetMinute 示例中修改了 Android HomeView - https://github.com/slodge/MvvmCross-Tutorials/tree/master/InternetMinute
using Android.App;
using Android.OS;
using Cirrious.CrossCore;
using Cirrious.MvvmCross.Droid.Views;
using Cirrious.MvvmCross.Plugins.Messenger;
using InternetMinute.Core;
namespace InternetMinute.Droid.Views
{
[Activity(Label = "Internet time is ticking")]
public class HomeView : MvxActivity
{
private MvxSubscriptionToken _token;
private IMvxMessenger _messenger;
protected IMvxMessenger Messenger
{
get
{
_messenger = _messenger ?? Mvx.Resolve<IMvxMessenger>();
return _messenger;
}
}
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.HomeView);
}
protected override void OnResume()
{
base.OnResume();
_token = Messenger.SubscribeOnMainThread<TickMessage>(OnTick);
}
protected override void OnPause()
{
Messenger.Unsubscribe<TickMessage>(_token);
_token = null;
base.OnPause();
}
private int _i = 0;
private void OnTick(TickMessage obj)
{
Mvx.Trace("Tick received {0}", ++_i);
}
}
}
这似乎工作正常 - 我得到了我所期待的踪迹。
也许您的 SubscribeOnMainThread 没有订阅正确的消息类型 - 编译器推断出什么类型?