Delphi TNotificationCenter Multiple Repeating Notifications has unexpected behaviour

狂风中的少年 提交于 2020-01-24 15:45:07

问题


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

来源:https://stackoverflow.com/questions/34719635/delphi-tnotificationcenter-multiple-repeating-notifications-has-unexpected-behav

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!