Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了MvvmCross在Android通知点击导航到ViewModel大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用Support.V7.NotificationCompat显示通知.我想在单击此通知时导航到viewmodel.当我尝试使用Mvxviewmodel@R_674_10613@est显示viewmodel时,我传递给viewmodel的导航参数不起作用,但是当我像这样使用Showviewmodel时它可以工作:

Showviewmodel<RouteModificationviewmodel>(new { id = exisTingModification.Id });

这是viewmodel Init方法.当我使用Showviewmodel导航时,Guid具有正确的值.当我使用Mvxviewmodel@R_674_10613@est导航时,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(@L_852_18@manager.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 @R_674_10613@est = Mvxviewmodel@R_674_10613@est<RouteModificationviewmodel>.GetDefault@R_674_10613@est();
    var json = Mvx.Resolve<IMvxJsonConverter>().serializeObject(new { id = guid });
    @R_674_10613@est.PresentationValues = new Dictionary<String,String>
    {
        { "id",json }
    };
    var translator = Mvx.Resolve<IMvxAndroidviewmodel@R_674_10613@estTranslator>();
    var intent = translator.GeTintentFor(@R_674_10613@est);
    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所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。