Search code examples
androidbroadcastreceiver

start a another version of an existing broadcastreceiver


I have a fragment with a button that starts a BroadcastReceiver. This BroadcastReciever creates a notification after a time retrieved from the fragment. This part works. However, when I press the button more than once, the existing broadcast receiver is overwritten. I don't want this as I want multiple notifications to be created.

Any solutions?

Thank you


Solution

  • I found the answer - The pending intent used in the alarm manager was not unique so it was overwritten each time I created another alarm. What I needed to do was create multiple alarms. This is done by adding a unique id to the 2nd parameter (argument?) of the pending intent.

    See this answer for more details: https://stackoverflow.com/a/10090378/2442638