Delphi TNotificationCenter Multiple Repeating Notifications has unexpected behaviour

  

lets say you want to create a Notification with a repeat interval so that it is recurring

var
MyNotification : TNotification;
begin
MyNotification := NotificationCenter1.CreateNotification;
try
MyNotification.Name := ‘FirstNotification’;
MyNotification.AlertBody := ‘First Notification!’;
MyNotification.FireDate := IncSecond(Now,15);// Note this fires 15 secs from NOW
MyNotification.RepeatInterval := TRepeatInterval.Minute;
Notificationcenter1.ScheduleNotification(MyNotification);
finally
MyNotification.DisposeOf;
end;

In my case it is recurring to remind the user to respond to the notification, and then Once the user responds to the Notification on the TNotificationCenters OnReceiveLocalNotification I simply cancel the notification

NotificationCenter1.CancelNotification(ANotification.Name);

this cancels the notification and it works(kind of)

Now the above example will create a notification and once every minute if it is not responded to it will fire again, and again till responded to.

But the problem now is if I would to create another notification that I also want to repeat:

var
MyNotification2 : TNotification;
begin
MyNotification2 := NotificationCenter1.CreateNotification;
try
MyNotification2.Name := ‘SecondNotification’;
MyNotification2.AlertBody := ‘Second Notification!’;
MyNotification2.FireDate := IncSecond(Now,30);// Note this fires 30 secs from NOW
MyNotification2.RepeatInterval := TRepeatInterval.Minute;
Notificationcenter1.ScheduleNotification(MyNotification2);
finally
MyNotification2.DisposeOf;
end;

if the Second Notification’s FireDate is set to later than the first then it all works fine and dandy as expected, BUT if I was to Create the Second Notification with a FireDate like IncSecond(Now,10) meaning it will fire before the first scheduled Notification things go wrong

var
MyNotification2 : TNotification;
begin
MyNotification2 := NotificationCenter1.CreateNotification;
try
MyNotification2.Name := ‘SecondNotification’;
MyNotification2.AlertBody := ‘Second Notification!’;
MyNotification2.FireDate := IncSecond(Now,10);// Note this fires 10 secs from NOW
MyNotification2.RepeatInterval := TRepeatInterval.Minute;
Notificationcenter1.ScheduleNotification(MyNotification2);
finally
MyNotification2.DisposeOf;
end;

The First Notification never arrives and the second Notification is no longer removed by NotificationCenter1.CancelNotification(ANotification.Name);
the CancelNotification will now have no effect on the SecondNotification

Update 1

I can confirm that the code works exactly as it should (No unexpected behaviour) in iOS so this is a Android related issue,

I have tried it on Xperia Z2 running 5.0.2 and a Samsung Note 2 running 4.4.2 and the behaviour is exactly the same

Comments are closed.