I have a Xamarin Forms application which raises an Android Notification but I'm having trouble creating a simple page that will interact with the user when they click the Notification. I understand that in Xamarin.Forms there is only 1 activity and so the pending Intent must be to that mainActivity
I have set the LaunchMode to SingleTop and and Intent Filter to match the Intent name used in the pendingIntent
Now when I click the Notification I do get routed to the OnResume of the MainActivity but I don't understand how to: 1) Recognise that I am in this activity because of the notification click - I tried adding an Extra to the pending Intent but it is not there when I inspect this.Intent.Extras 2) Even if I know that I'm in the activity due to the notification click, how do I launch a specific page from the Activity. I'm new to Xamarin but I can't see how to navigate to a Content Page or access the Navigation Stack.
This must be a really common use case but I can't find anything relevant.
Ensure the you have set
LaunchMode.SingleTop
on yourMainActivity
:LaunchMode.SingleTop
In your
MainActivity
(the FormsAppCompatActivity subclass) add aOnNewIntent
override:OnNewIntent:
Now you can check the
intent.Action
/intent.HasExtra
to determine if it is your notification that was send and thus process it. WithXamarin.Forms
the easiest would be to useMessagingCenter
to send a message that is subscribed to within your .NetStd/PCLXamarin.Forms
code base.NotificationClickedOn: