title: How can I receive push notifications when my app is closed?
body: <p><strong><em>This is the Messaging service class</em></strong> </p>
  
  <pre><code>[Service]
      [IntentFilter(new[] { "com.google.firebase.MESSAGING_EVENT" })]
      class MyFirebaseMessagingService : FirebaseMessagingService
      {
          public override void OnMessageReceived(RemoteMessage message)
          {
              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);
  
          var defaultSoundUri = RingtoneManager.GetDefaultUri(RingtoneType.Notification);
          var notificationBuilder = new NotificationCompat.Builder(this)
              .SetSmallIcon(Resource.Drawable.Notification)
              .SetContentTitle("")
              .SetContentText(body)
              .SetAutoCancel(true)
              .SetSound(defaultSoundUri)
              .SetContentIntent(pendingIntent);
  
          var notificationManager = NotificationManager.FromContext(this);
          notificationManager.Notify(0, notificationBuilder.Build());
      }
  </code></pre>
  
  <p><strong><em>this is the firebase id class</em></strong></p>
  
  <pre><code> [Service]
      [IntentFilter(new[] { "com.google.firebase.INSTANCE_ID_EVENT" })]
      class MyFirebaseIdService : FirebaseInstanceIdService
      {
  
      public override void OnTokenRefresh()
      {
      base.OnTokenRefresh();
      Android.Util.Log.Debug("Refreshed Token:", 
      FirebaseInstanceId.Instance.Token);
      }
  </code></pre>
  
  <p><strong><em>This is the main activity</em></strong></p>
  
  <pre><code>Task.Run(() =&gt; {
  var instanceId = FirebaseInstanceId.Instance;
  instanceId.DeleteInstanceId();
  Android.Util.Log.Debug("TAG", "{0} {1}", instanceId.Token, 
  instanceId.GetToken(GetString(Resource.String.gcm_defaultSenderId), 
  Firebase.Messaging.FirebaseMessaging.InstanceIdScope));
  
  
  });
  </code></pre>