Showviewmodel<RouteModificationviewmodel>(new { ID = existingModification.ID });
这是viewmodel Init方法.当我使用Showviewmodel导航时,GuID具有正确的值.当我使用MvxviewmodelRequest导航时,GuID总是具有值GuID.Empty(全0).
public voID Init(GuID ID){ _routeModificationID = ID;}
这就是我试图从通知中显示viewmodel的方式:
public voID ShowRouteModifiednotification(RouteModificationModel routeModificationModel){ var context = Application.Context; var builder = new NotificationCompat.Builder(context); builder.SetDefaults(NotificationCompat.DefaultAll); builder.Setcategory(NotificationCompat.categoryStatus); builder.SetautoCancel(true); builder.SetPriority(NotificationCompat.PriorityHigh); builder.SetSmallicon(Resource.Mipmap.ic_launcher); builder.SetContentTitle("Route Modification"); builder.SetContentText("Hello,World!"); builder.SetContentIntent(GetIntent(routeModificationModel.ID)); builder.SetVibrate(new long[] { 1000,1000,1000 }); builder.SetSound(ringtoneManager.GetDefaultUri(ringtoneType.Notification)); var notification = builder.Build(); var notificationmanager = (notificationmanager)context.GetSystemService(Context.NotificationService); var handler = new Handler(Looper.MainLooper); handler.Post(() => { notificationmanager.Notify(RouteModificationNotificationID,notification); });}private PendingIntent GetIntent(GuID guID){ var request = MvxviewmodelRequest<RouteModificationviewmodel>.GetDefaultRequest(); var Json = Mvx.Resolve<IMvxJsonConverter>().SerializeObject(new { ID = guID }); request.PresentationValues = new Dictionary<string,string> { { "ID",Json } }; var translator = Mvx.Resolve<IMvxAndroIDviewmodelRequestTranslator>(); var intent = translator.GetIntentFor(request); return PendingIntent.GetActivity(Application.Context,intent,0);}
谁能看到我错过的或做错了什么?
解决方法 MvvmCross此后收到了MvvmCross 5.0及更高版本中导航工作方式的重大更新.如果您使用的是MvvmCross 4.x或3.x,则此问题可能仅适用.在这种情况下,4.x中的MvvmCross导航API未正确序列化GuID.您可以通过将GuID序列化为字符串并将字符串作为导航参数传递,然后将字符串反序列化为viewmodel中的GuID来解决此问题. 总结以上是内存溢出为你收集整理的MvvmCross在Android通知点击导航到ViewModel全部内容,希望文章能够帮你解决MvvmCross在Android通知点击导航到ViewModel所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)