Android Question my first service, some questions

Himred

Member
Licensed User
Longtime User
Hello everybody,

I'm currently creating my first service, so far thanks to the tutorial i have been able to make it work.
I have chosen the startforeground way to make sure it won't get killed by the OS.

I have done it the standard way:
B4X:
sNotif.Initialize
sNotif.Icon = "icon"
sNotif.SetInfo("xxxx","yyyy",Main)
sNotif.Sound = False
sNotif.Light = False
sNotif.Vibrate = False
sNotif.Notify(1)  
Service.StartForeground(1,sNotif)

Now some users complains that the notification cannot get removed (that's logical).
Some of them used this trick: they edited the app preference in OS and disabled the "show notification" option.
That seems to hide everything without the service beeing killed.

Is there a way to achieve the same without manual trickery from the user ?
ie can I keep the service up without the notification on the home screen (the icon of status bar could be ok).

Thanks !

Himred
 

KMatle

Expert
Licensed User
Longtime User
A notification has nothing todo with a service. It's just a notification.

I use this (which can be removed by the user):

B4X:
Dim n As Notification
n.Initialize
n.Icon = "icon"
n.SetInfo2("AppsName","This is a message","Noti", "")
n.Notify(1)

Idea of a notification is to notify the user that

- an app is running
- there is just a message

In both situations I wouldn't pin it. Let the user decide. Even if the app is killed, at the start of the next service you can notify again.

So if you want to notify the user every x time just use the code from above from the service and start the service again with "StartAt".
 
Upvote 0
Top