codenameone / CodenameOne

Cross-platform framework for building truly native mobile apps with Java or Kotlin. Write Once Run Anywhere support for iOS, Android, Desktop & Web.
https://www.codenameone.com/
Other
1.71k stars 408 forks source link

RFE: Extend Local Notifications API with support for a cancelAll() to remove all previously activated local notifications #1769

Open ThomasH99 opened 8 years ago

ThomasH99 commented 8 years ago

I have a use case where I use local notifications for reminders. As discussed many places, iOS (and hence CN1) doesn't support setting arbitrary repeat intervals, so to implement this you typically set multiple notifications for the same reminder. However, when you need to update the already activated reminders, it becomes pretty complex to keep track of which have been set previously and remove each one explicitly using Display.cancelLocalNotification(String notificationId).

This would be much simpler with support to cancel all the previously set local notifications in one go and then simply recreate the appropriate ones.

I can see that iOS has this support (cancelAllLocalNotifications), so hopefully it is possible to reflect this in the CN1 API.

ThomasH99 commented 8 years ago

Hi Chen, any chance you will be able to squeeze this into the upcoming release?

It is almost indispensable to my use case since keeping track of all active notications (e.g. to know exactly which to remove when reminders are changed) would require a kind of double bookkeeping by storing every set notivation in local storage as well, which would be complex and error prone.

chen-fishbein commented 8 years ago

There is no underlying API to do so, why can't you use the available repeating notifications?

ThomasH99 commented 8 years ago

Hi Chen, To answer your question first: the intervals for repeating notifications only allows a few hard-coded intervals, so to support any other interval you need a different mecanism, and it seems the common approach used is to set multiple separate notifications.

Actually, thinking about this again, the real problem is to keep track of already created local notifications without having to store this locally. So, the most general extension of the API would probably be a call that allows you to get the list of already set local notifications. Then you can delete them, update them or whatever is necessary and you don't risk to 'leave one behind' that you lost track of. I believe I saw that this API existed on both iOS and Android when I checked before creating this request.