Android 收到推送通知且应用程序关闭时应用程序崩溃

Android 收到推送通知且应用程序关闭时应用程序崩溃,android,xamarin,xamarin.forms,crash,android-notifications,Android,Xamarin,Xamarin.forms,Crash,Android Notifications,收到推送通知时,我的Xamarin Android应用程序崩溃 以下是错误: System.NotSupportedException:无法将Java类型为“md53ff9574f15073ce2830b1527af878807/GcmListener”的JNI句柄0xbee2dcd8(密钥句柄0x1302a92b)激活为托管类型“DriversInfo.Droid.GcmListener”。-->System.ArgumentNullException:值不能为null 以下是接收通知的代码(

收到推送通知时,我的Xamarin Android应用程序崩溃

以下是错误:

System.NotSupportedException:无法将Java类型为“md53ff9574f15073ce2830b1527af878807/GcmListener”的JNI句柄0xbee2dcd8(密钥句柄0x1302a92b)激活为托管类型“DriversInfo.Droid.GcmListener”。-->System.ArgumentNullException:值不能为null

以下是接收通知的代码(GCMListener):

以及显示通知的代码:

        public static bool DisplayNotification(Context context, string title, string desc,
                                           NotificationId notificationId = 0)
    {
        // Set up an intent so that tapping the notifications returns to this app:
        Intent intent = new Intent(context, typeof(MainActivity));
        intent.SetFlags(ActivityFlags.ClearTop | ActivityFlags.SingleTop);

        // Create a PendingIntent; we're only using one PendingIntent (ID = 0):
        const int pendingIntentId = 0;
        PendingIntent pendingIntent =
            PendingIntent.GetActivity(context, pendingIntentId, intent, PendingIntentFlags.UpdateCurrent);

        var builder = new NotificationCompat.Builder(context)
            .SetAutoCancel(true)
            .SetContentTitle(title)
            .SetContentText(desc)
            .SetContentIntent(pendingIntent)
            .SetSmallIcon(Resource.Drawable.Logo);

        //if (Settings.AppAcceptsSoundNotifications)
        builder.SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification));

        // Build the notification:
        var notification = builder.Build();

        // Get the notification manager:
        var notificationManager = context.GetSystemService(Context.NotificationService) as NotificationManager;

        notificationManager?.Notify((int) notificationId, notification);
        return true;
    }
我没有写这段代码,我想了解更多! 我对新的Xamarin/Android开发者有点失望,需要社区帮助/解释

谢谢;)

编辑

以下是有关应用程序崩溃的更多详细信息(无上下文):

AndroidRuntime参数名称:Autofac.ResolutionExtensions.ResolveService处的上下文(Autofac.IComponentContext,Autofac.Core.Service,System.Collections.Generic.IEnumerable
1[T]参数)[0x00003]in:0处的Autofac.ResolutionExtensions.Resolve(Autofac.IComponentContext,System.Type serviceType,System.Collections.Generic.IEnumerable
1[T]参数)[0x00007]in:0在Autofac.ResolutionExtensions.Resolve[TService](Autofac.IComponentContext,System.Collections.Generic.IEnumerable`1[T]参数)[0x00000 in:0在Autofac.ResolutionExtensions.Resolve[TService](Autofac.IComponentContext上下文)[0x00000]in:0位于DriversInfo.Droid.GcmListener..ctor()[0x0000c]in:0位于(包装器动态方法)System.Object.6e5c2775-7f90-4dd7-a6af-e9481e583260(intptr,Object[]),位于Java.Interop.TypeManager.n_(System.IntPtr jnienv、System.IntPtr jclass、System.IntPtr typename_ptr、System.IntPtr signature_ptr、System.IntPtr jobject、System.IntPtr parameters_ptr)[0x000df]in:0---内部异常堆栈跟踪的结束---在Java.Interop.TypeManager.n\u处激活(System.IntPtr jnienv,System.IntPtr jclass,System.IntPtr typename_ptr,System.IntPtr signature_ptr,System.IntPtr jobject,System.IntPtr parameters_ptr)[0x00168]in:0 at(包装器动态方法)System.Object.ae816e3f-b83f-4390-af32-80f1fa8830a2(IntPtr,IntPtr,IntPtr,IntPtr,IntPtr,IntPtr,IntPtr,IntPtr,IntPtr,IntPtr)在mono.android.TypeManager.n激活(本机方法)在md5c4b050970b34fabb7ecdb34ca8ce9387.GcmListener.java.23中的mono.android.TypeManager.Activate(TypeManager.java:7)在java.lang.reflect.Constructor.newInstance(本机方法)在java.lang.Class.newInstance(Class.java:1690)在android.app.ActivityThread.handleCreateService(ActivityThread.java:3657)中android.app.ActivityThread.access$2000(ActivityThread.java:219)android.app.ActivityThread$H.handleMessage(ActivityThread.java:1818)android.os.Handler.dispatchMessage(Handler.java:102)android.os.Looper.loop(Looper.java:145)android.app.ActivityThread.main(ActivityThread.java:6939)java.lang.reflect.Method(本机方法)invoke(本机方法)java.lang.reflect.Method.invoke(Method.java:372)位于com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)位于com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)


System.ArgumentNullException:值不能为null。
您需要调试它以确定什么是
null
,它是来自
数据的
,等等……我无法调试,因为应用程序此时已关闭!您知道怎么做吗?
        public static bool DisplayNotification(Context context, string title, string desc,
                                           NotificationId notificationId = 0)
    {
        // Set up an intent so that tapping the notifications returns to this app:
        Intent intent = new Intent(context, typeof(MainActivity));
        intent.SetFlags(ActivityFlags.ClearTop | ActivityFlags.SingleTop);

        // Create a PendingIntent; we're only using one PendingIntent (ID = 0):
        const int pendingIntentId = 0;
        PendingIntent pendingIntent =
            PendingIntent.GetActivity(context, pendingIntentId, intent, PendingIntentFlags.UpdateCurrent);

        var builder = new NotificationCompat.Builder(context)
            .SetAutoCancel(true)
            .SetContentTitle(title)
            .SetContentText(desc)
            .SetContentIntent(pendingIntent)
            .SetSmallIcon(Resource.Drawable.Logo);

        //if (Settings.AppAcceptsSoundNotifications)
        builder.SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification));

        // Build the notification:
        var notification = builder.Build();

        // Get the notification manager:
        var notificationManager = context.GetSystemService(Context.NotificationService) as NotificationManager;

        notificationManager?.Notify((int) notificationId, notification);
        return true;
    }