Android Question Automatic foreground services

aaronk

Well-Known Member
Licensed User
Longtime User
Hi,

I have read the tutorial about the automatic foreground services - https://www.b4x.com/android/forum/threads/automatic-foreground-mode.90546/#content

I have a service running and I have the code:

B4X:
Sub Service_Destroy
    StartServiceAt(Me, DateTime.Now + 5 * 1000, False) 'will start after 5 seconds.
End Sub

As you have noticed I put that code in Service_Destroy.

I was hoping to keep this service running 24/7 and never have it stop running.

The issue I have is, about 1 minute after the app is closed (not showing on the screen) this service is killed and Service_Destroy is called.

This then starts the service again 5 seconds later since my code is telling it to start again. However a notification is then shown in the system notification tray.

Is there a way in running the service again without this notification showing, but keep the service running?
Or, is there a way in changing the text of the notification rather than just the app title?
 

aaronk

Well-Known Member
Licensed User
Longtime User
So I need to use:

Service_Create
B4X:
Service.AutomaticForegroundMode = Service.AUTOMATIC_FOREGROUND_NEVER
lock.PartialLock

And in in Service_Start I need to use:
B4X:
Service.StartForeground(nid, CreateNotification("..."))

Without using the Service.StartForeground then it will kill the service after approx. 1 minute ?

Is there a way in not showing the notification ?

I also noticed you have the following code in the same service:
B4X:
StartServiceAt(Me, DateTime.Now + 30 * DateTime.TicksPerMinute, True)

Is that just in case the service is killed so it can start again ?
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…