关于这个问题,我为类似这样的消息服务实现了一个插件:
var activity = Mvx.Resolve<IMvxAndroidCurrentTopActivity>().Activity;
var context = activity.ApplicationContext;
var request = MvxViewModelRequest<MyViewModel>.GetDefaultRequest();
request.ParameterValues = new Dictionary<string, string> { { "setId", setId.ToString() } };
var translator = Mvx.Resolve<IMvxAndroidViewModelRequestTranslator>();
var intent = translator.GetIntentFor(request);
var pending = PendingIntent.GetActivity(context, 0, intent, 0);
var builder = new NotificationCompat.Builder(context)
.SetContentTitle(title)
.SetSmallIcon(Resource.Drawable.Icon)
.SetContentText(message)
.SetContentIntent(pending);
var notificationManager = (NotificationManager)activity.ApplicationContext.GetSystemService(Context.NotificationService);
notificationManager.Notify(0, builder.Build());
通知会打开此 ViewModel:
public class MyViewModel : MvxViewModel
{
...
public void Init(int setId){...}
...
}
问题是,ViewModel 中的 myId 始终是第一个通知中的 Id,即使 ParemeterValues 已正确更新。
有任何想法吗?