So I just implemented FCM in my Xamarin.Forms Android app with this guide. Everything works pretty well, the notifications arrive, they play a sound, have an icon etc. Then I wanted to add an action to my notification, it has to open a certain page in my app.
And thats were my problem comes in, Xamarin.Forms puts all Android content in a single Activity. Which means that opening a certain page causes the whole OnCreate of the MainActivity to load again (And the LoadApplication as well).
My Notification
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 Payload
{"data":{"message":"Notification Hub test notification", "action":"open-exam", "exam-id":"F50FC23C-B4EE-E611-80C3-000D3A218F79"}}
So my question is, how to open a Xamarin.Forms page without reloading the entire app on Android?