title: Cancel an alarm in Xamarin.forms (Android)
body: <p>I've read a lot about canceling notifications/alarms but I can't get it working. I set up a test where I create a alarm and immediately delete it. But it keeps firing.</p>
  
  <p>Code to create / delete alarms (called 14 times with increasing notificationId):</p>
  
  <pre><code>public void CreateNotification(string title, string text, DateTime datetime, int notificationId)
  {
      var alarmIntent = new Intent(Forms.Context, typeof(NotificationAlarmReceiver));
      alarmIntent.SetAction("com.tender.droid.notification");
  
      alarmIntent.PutExtra("text", text);
      alarmIntent.PutExtra("title", title);
      alarmIntent.PutExtra("notificationId", notificationId);
      alarmIntent.PutExtra("millisecond", datetime.Millisecond);
  
      var pendingIntent = PendingIntent.GetBroadcast(Forms.Context, notificationId, alarmIntent, PendingIntentFlags.UpdateCurrent);
      var alarmManager = (AlarmManager)Forms.Context.GetSystemService(Context.AlarmService);
  
      alarmManager.Set(AlarmType.RtcWakeup, (long)datetime.ToUniversalTime().Subtract(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds, pendingIntent);
  
      DeleteNotification(notificationId);
  }
  
  public void DeleteNotification(int notificationId)
  {
      var notificationManager = Android.App.Application.Context.GetSystemService(Context.NotificationService) as NotificationManager;
      notificationManager.Cancel(notificationId);
  
      var alarmIntent = new Intent(Forms.Context, typeof(NotificationAlarmReceiver));
      var pendingIntent = PendingIntent.GetBroadcast(Forms.Context, notificationId, alarmIntent, PendingIntentFlags.UpdateCurrent);
      var alarmManager = (AlarmManager)Forms.Context.GetSystemService(Context.AlarmService);
      pendingIntent.Cancel();
      alarmManager.Cancel(pendingIntent);
  }
  </code></pre>
  
  <p>Code for class NotificationAlarmReceiver:</p>
  
  <pre><code>[BroadcastReceiver(Enabled = true, Process = ":remote")]
  [IntentFilter(new[] { "com.tender.droid.notification" })]
  public class NotificationAlarmReceiver : BroadcastReceiver
  {
      public override void OnReceive(Context context, Intent intent)
      {
          var text = intent.GetStringExtra("text");
          var title = intent.GetStringExtra("title");
          var notificationId = intent.GetStringExtra("notificationId");
  
          var notIntent = new Intent(context, typeof(SplashScreen));
          var contentIntent = PendingIntent.GetActivity(context, 0, notIntent, PendingIntentFlags.UpdateCurrent);
          var manager = NotificationManagerCompat.From(context);
  
          var style = new NotificationCompat.BigTextStyle();
          style.BigText(text);
  
          //Generate a notification with just short text and small icon, set notification elements:
          var builder = new NotificationCompat.Builder(context)
              .SetContentIntent(contentIntent)
              .SetSmallIcon(Resource.Drawable.android_notification)
              .SetContentTitle(title)
              .SetContentText(text)
              .SetStyle(style)
              .SetWhen(Java.Lang.JavaSystem.CurrentTimeMillis())
              .SetAutoCancel(true)
              .SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification));
  
          // Instantiate the builder
          var notification = builder.Build();
  
          manager.Notify(Convert.ToInt32(notificationId), notification);
      }
  }
  </code></pre>
  
  <p>Any help on this?</p>
  
  <p>Thanks</p>