title: App Reload on Push Notification Click Xamarin Forms
body: <p>I have implemented push notifications on my app and they work fine.
  The problem I have is that when I click them in the pull down menu they immediately reload the app. To counter this I had the app create a new activity instance. This now opens a new page but when clicking back from this new page it has the same problem and reloads the whole app again.</p>
  
  <p>I am using Xamarin Forms with PCL, so its not pure Android.
  Is there a way to get the click event on the menu item to load a specific page view in PCL? Reloading the whole app is kind of useless.</p>
  
  <p>This is the class the creates the phone notification:</p>
  
  <p>ForegroundMessages.cs:</p>
  
  <pre><code> [Service]
  [IntentFilter(new[] { "com.google.firebase.MESSAGING_EVENT" })]
  
  public class ForegroundMessages: FirebaseMessagingService
  {
  
  
      const string TAG = "MyFirebaseMsgService";
      public override void OnMessageReceived(RemoteMessage message)
      {
          //Log.Debug(TAG, "From: " + message.From);
          //Log.Debug(TAG, "Notification Message Body: " + message.GetNotification().Body);
          base.OnMessageReceived(message);
          SendNotification(message.GetNotification().Body);
      }
  
      private void SendNotification(string body)
      {
          var intent = new Intent(this, typeof(MainActivity));
          intent.AddFlags(ActivityFlags.ClearTop);
         // var pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.OneShot);
  
          Log.Debug(TAG, "Notification Message Body: " + body);
  
          // sends notification to view model
          MessagingCenter.Send((App)Xamarin.Forms.Application.Current, "Increase");
  
          Intent resultintent = new Intent(this,typeof(SecondActivity));
  
          TaskStackBuilder stackbuilder = TaskStackBuilder.Create(this);
          stackbuilder.AddParentStack(Java.Lang.Class.FromType(typeof(SecondActivity)));
          stackbuilder.AddNextIntent(resultintent);
  
          PendingIntent resultPendingIntent = stackbuilder.GetPendingIntent(0, (int)PendingIntentFlags.UpdateCurrent);
  
          var defaultSoundUri = RingtoneManager.GetDefaultUri(RingtoneType.Notification);
          var notificationBuilder = new NotificationCompat.Builder(this)
              .SetSmallIcon(Resource.Drawable.icon)
              .SetContentTitle("Notification")
              .SetContentText(body)
              .SetAutoCancel(true)
              .SetSound(defaultSoundUri)
              .SetContentIntent(resultPendingIntent);
  
          var notificationManager = NotificationManager.FromContext(this);
          notificationManager.Notify(0, notificationBuilder.Build());
      }
  
  
  }
  </code></pre>
  
  <p>and the Second Activity class:</p>
  
  <pre><code>  [Activity(Label = "Notifications")]
  public class SecondActivity:Activity
  {
  
      protected override void OnCreate(Bundle bundle)
      {
          base.OnCreate(bundle);
  
          System.Diagnostics.Debug.WriteLine("this worked");
      }
  
  }
  </code></pre>
  
  <p>As stated, this works and receives messages fine and when you click them it loads second activity but when moving away from the second activity page it just reloads the whole app again.
  It would be better if I could load a view page (.xaml or .xaml.cs) in the PCL rather than this.</p>
  
  <p>Any ideas?</p>