Multiple notification

stefanoa

Active Member
Licensed User
Longtime User
i need to create a notification for each new task that is created... so i call AlarmService with a different id (alarmID) every time I create a new task.

with this code considers only the last notification created :BangHead:

every time I save a new task i have to call this code:

(tmpAlarmID is a sequential number)

'--- Start service ---
AlarmService.DescriptionTitle="Title...."
AlarmService.DescriptionBody="Body....."
AlarmService.AlarmID=tmpAlarmID
StartServiceAt( AlarmService, Alarm, True)

the service (AlarmService) is:
Sub Service_Create

Notification1.Initialize
Notification1.Icon = "icon" 'use the application icon file for the notification
Notification1.Vibrate = True
Notification1.SetInfo(DescriptionTitle, DescriptionBody, "")
Notification1.Sound = True

End Sub

Sub Service_Start (StartingIntent As Intent)
Notification1.Notify (alarmID)
End Sub

any suggestions? thanks
 
Last edited:

stefanoa

Active Member
Licensed User
Longtime User
same problem..

is activated only the last notification inserted... :-(


Sub Service_Start (StartingIntent As Intent)

Notification1.Initialize
Notification1.Icon = "icon" 'use the application icon file for the notification
Notification1.Vibrate = True
Notification1.SetInfo(DescriptionTitle, DescriptionBody, "")
Notification1.Sound = True
Notification1.AutoCancel =True
Notification1.Notify (alarmID)

End Sub
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Make sure that the ID is different each time. I've just tested the following code and it works as expected:
B4X:
Dim notification1 As Notification
notification1.Initialize
notification1.Icon = "icon" 'use the application icon file for the notification
notification1.Vibrate = True
notification1.SetInfo("sdfsdf", "fwefwef", "")
notification1.Sound = True
notification1.AutoCancel =True
notification1.Notify (1)

notification1.Initialize
notification1.Icon = "icon" 'use the application icon file for the notification
notification1.Vibrate = True
notification1.SetInfo("sdfsdf", "fwefwef", "")
notification1.Sound = True
notification1.AutoCancel =True
notification1.Notify (2)

notification1.Initialize
notification1.Icon = "icon" 'use the application icon file for the notification
notification1.Vibrate = True
notification1.SetInfo("sdfsdf", "fwefwef", "")
notification1.Sound = True
notification1.AutoCancel =True
notification1.Notify (3)
 
Upvote 0

stefanoa

Active Member
Licensed User
Longtime User
i think the problem is the Service because the ID is different but i call the same service every time.. :BangHead:

Main: (whe in save a new task):

'--- start service ---
AlarmService.DescriptionTitle=descriptionedittext.Text
AlarmService.DescriptionBody="id:" & tmLastAlertID
AlarmService.AlarmID=tmLastAlertID '>> sequential

StartServiceAt(AlarmService, Alarm, True)
....

AlarmService:

Sub Service_Start (StartingIntent As Intent)

Notification1.Initialize
Notification1.Icon = "icon" 'use the application icon file for the notification
Notification1.Vibrate = True
Notification1.SetInfo(DescriptionTitle, DescriptionBody, "")
Notification1.Sound = True
Notification1.AutoCancel =True
Notification1.Notify (alarmID)

End Sub
 
Upvote 0

stefanoa

Active Member
Licensed User
Longtime User
but it is correctly launch more times the same service with different dates and times? Could this be the problem?

otherwise I should create different instances of the same service .. but how?
 
Upvote 0

stefanoa

Active Member
Licensed User
Longtime User
So this is the problem!!!

Remember that every call to StartServiceAt cancels previous calls.

So how can I do to plan multiple services at different times?
 
Upvote 0
Top