Xamarin MVVMCross ViewModel与Android服务通信

Xamarin MVVMCross ViewModel与Android服务通信,xamarin,xamarin.android,android-service,mvvmcross,Xamarin,Xamarin.android,Android Service,Mvvmcross,我需要一些关于项目架构的帮助我无法了解ViewModel如何与Android服务通信。 我创建了一个接口,可以调用一些平台函数: 公共接口IGeoLocationWatcher { 地理位置{get;set;} void StartLocationService(); void StopLocationService(); } 在android平台上,我使用如下界面: [服务] 公共类DroidGeolocationWatcher:服务, Android.Gms.Common.api.Goog

我需要一些关于项目架构的帮助我无法了解ViewModel如何与Android服务通信。 我创建了一个接口,可以调用一些平台函数:

公共接口IGeoLocationWatcher
{
地理位置{get;set;}
void StartLocationService();
void StopLocationService();
}
在android平台上,我使用如下界面:

[服务]
公共类DroidGeolocationWatcher:服务,
Android.Gms.Common.api.GoogleAppClient.IConnectionCallbacks,
Android.Gms.Common.api.GoogleAppClient.IOnConnectionFailedListener,
Android.Gms.Location.ILocationListener,
IGeoLocationWatcher
{
公共地理位置{get;set;}
公共定位服务();
公共无效StopLocationService();
}
当我获得一个新位置时,我调用在ViewModel中订阅的自定义消息(事件)。 如果应用程序在后台运行,我会发送通知,或者在前台运行,我会更新我的UI

WeakSubscribe((s)=>{
位置=s;
RaisePropertyChanged(()=>位置);
});
但它似乎不起作用。我需要一些建议,我做错了什么,或者另一种方法


感谢您的关注。

subscribe方法返回类型为
MvxValueEventSubscription
的令牌。您需要将该令牌存储在视图模型的属性中,否则该令牌可能会在收到通知之前被释放

如果要停止接收通知,可以执行以下操作:

if (this.token != null)
{
this.token.Dispose();
this.token = null;
}