Android Question a way to suppress notification for Service.StartForeground

aeropic

Active Member
Licensed User
Longtime User
In the tutorial Difference between static and dynamic receivers
it is stated : Normal processes eventually get killed. . A possible workaround is to call Service.StartForeground in the service. This will prevent the process from being killed. However this will also add an ongoing notification icon (see the Services tutorial for more information).

I have discovered a way to get rid of the notification:

The trick is to define the notification with an empty string icon ...

B4X:
sNotif.Initialize
    sNotif.Icon = ""  ' empty string will cancel notification ...
    sNotif.OnGoingEvent = True
    sNotif.SetInfo("Camera unlock","Service Running",second)
    sNotif.Sound = False
    sNotif.Vibrate = False
    sNotif.Notify(1)
    Service.StartForeground(1,sNotif)

But I don't know if it is correct and if the service will remain "started foreground" forever ? (once started, the service appears as foreground)

Alain
 
Top