Notification problem with AutoCancel

stefanoa

Active Member
Licensed User
Longtime User
Notification problem with Delete or AutoCancel

Hi,
i've create a service (AlarmService) with:
B4X:
'---------------------------------------------------------
Sub Process_Globals
 Dim AlarmID As Int
 Dim DescriptionTitle As String
 Dim DescriptionBody As String
 Dim DoneSuccessfully As Boolean
 Dim Notification1 As Notification
End Sub

Sub Service_Create

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

End Sub

Sub Service_Start (StartingIntent As Intent)

 Service.StartForeground(1, Notification1) 

End Sub
'----------------------------------

notification is activated properly !!

1) Why clicking on the notification can not be erased automatically? (Notification1.AutoCancel =True)

2) if I try to manually delete it by ID, notification is NOT DELETED!!!

in Main:

Sub AlarmReset

Dim noti As Notification
noti.Cancel(1)

ToastMessageShow(trans.GetText("ALARM CANCELED") & " (ID: " & tmpAlertID & ")", False)

End Sub

thanks
 
Last edited by a moderator:

stefanoa

Active Member
Licensed User
Longtime User
you can give me an example of how to call Service.StopForeground ?

or is there a better way to open a notification rather than Service.StartForeground ?

i've to set an alarm (or notification) from a task....

thanks
 
Upvote 0

stefanoa

Active Member
Licensed User
Longtime User
with Notification.Notify and a service, the single notification is ok.
thanks
 
Last edited:
Upvote 0

hookshy

Well-Known Member
Licensed User
Longtime User
I encountered the same problem and I still have small question
is there a difference between
1 .nofification.nofify
2 .Service.StartForeground(1,notification) ??

I did not called startforeground but yet as I defined the notification to autocancel it won't work with nortification.cancel !


The solution remains to call
CallSub(myservice,"off_front") where off_front will stop foreground state of the service.
Please coment to clear things out about notification.cancel option !
Thanks
 
Upvote 0

hookshy

Well-Known Member
Licensed User
Longtime User
this is from Erel's tutorial and it works just fine
All parameters must be difined in the same place with the nofification.initialise statement
nofification.notify can be triggered when needed.

B4X:
Sub Activity_Create(FirstTime As Boolean)
    Dim n1, n2 As Notification
    n1.Initialize
    n1.Icon = "icon"
    n1.SetInfo("n1", "n1", "")
    n2.Initialize
    n2.Icon = "icon"
    n2.SetInfo("n2", "n2", "")
    n1.Notify(1)
    n2.Notify(2)
End Sub
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…