所以我只是在我的 Xamarin.Forms Android 应用程序中实现了 FCM本指南 https://learn.microsoft.com/en-us/azure/app-service-mobile/app-service-mobile-xamarin-forms-get-started-push。一切都运行良好,通知到达,它们播放声音,有图标等。然后我想向我的通知添加一个操作,它必须在我的应用程序中打开某个页面。
这就是我的问题所在,Xamarin.Forms 提出all单个 Activity 中的 Android 内容。这意味着打开某个页面会导致 MainActivity 的整个 OnCreate 再次加载(以及 LoadApplication )。
我的通知
var notificationIntent = new Intent(this, typeof(MainActivity));
notificationIntent.AddFlags(ActivityFlags.ClearTop | ActivityFlags.NewTask);
notificationIntent.PutExtras(intent.Extras);
var pendingIntent = PendingIntent.GetActivity(this, 0, notificationIntent, PendingIntentFlags.UpdateCurrent);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.SetSmallIcon(Resource.Drawable.icon)
.SetStyle(new NotificationCompat.BigTextStyle().BigText(text))
.SetContentIntent(pendingIntent)
.SetAutoCancel(true)
.SetPriority((int)NotificationPriority.Max)
.SetVibrate(new long[] { 0, 250, 100, 250, 0 })
.SetLights(Color.Red, 1, 250)
.SetContentTitle("Eindexamen")
.SetContentText(text);
FCM有效负载
{"data":{"message":"Notification Hub test notification", "action":"open-exam", "exam-id":"F50FC23C-B4EE-E611-80C3-000D3A218F79"}}
所以我的问题是,如何在 Android 上打开 Xamarin.Forms 页面而不重新加载整个应用程序?