开发者

Group Status Bar Notifications - One Icon

I have up to 4 separate alarms. When an alarm goes off, I display a status bar notification. If I have 2 alarms go off at the same time, I want to have only 1 status bar icon. If I cancel one of the two alarms, I still want to see that single status bar icon (since there is still an alar开发者_Go百科m going off, even though I cancelled the first alarm). When I cancel the last alarm on the screen I want to remove the status bar icon.

Is there a built in way to do this or do I have to keep track of what alarms are on the screen and only dismiss the notification if it's the last alarm?

Thanks for your help.


What I understood that you want only latest notification to be displayed and if you cancel your last alarm all should go. Here is my solution:

  1. Call the same notification function every time you set notification as it will replace the previous one.

  2. Pass an argument to notification function in case you want to cancel the notification.

  3. If a notification is alredy there and now you want to cancel the next alarm and you want the previous notification should be there, then you should maintain a variable in sharedpreference which will tell you not to cancel the previous notification.You should check this before calling notification function

  4. When you cancel the last alarm then you can pass the argument to notification function as you cancel any other alarm.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜