aaronk Well-Known Member Licensed User Longtime User Dec 17, 2018 #1 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: Code: 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?
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: Code: 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?
Erel B4X founder Staff member Licensed User Longtime User Dec 17, 2018 #2 StartServiceAt interval should be 30 minutes or more. Otherwise the OS will prevent the process from starting. The only way to keep a service running in the background is with a foreground service. See this example: https://www.b4x.com/android/forum/threads/background-location-tracking.99873/#content Upvote 0
StartServiceAt interval should be 30 minutes or more. Otherwise the OS will prevent the process from starting. The only way to keep a service running in the background is with a foreground service. See this example: https://www.b4x.com/android/forum/threads/background-location-tracking.99873/#content
aaronk Well-Known Member Licensed User Longtime User Dec 17, 2018 #3 So I need to use: Service_Create Code: Service.AutomaticForegroundMode = Service.AUTOMATIC_FOREGROUND_NEVER lock.PartialLock And in in Service_Start I need to use: Code: 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: Code: StartServiceAt(Me, DateTime.Now + 30 * DateTime.TicksPerMinute, True) Is that just in case the service is killed so it can start again ? Upvote 0
So I need to use: Service_Create Code: Service.AutomaticForegroundMode = Service.AUTOMATIC_FOREGROUND_NEVER lock.PartialLock And in in Service_Start I need to use: Code: 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: Code: StartServiceAt(Me, DateTime.Now + 30 * DateTime.TicksPerMinute, True) Is that just in case the service is killed so it can start again ?
Erel B4X founder Staff member Licensed User Longtime User Dec 17, 2018 #4 aaronk said: Without using the Service.StartForeground then it will kill the service after approx. 1 minute ? Click to expand... It will crash if the service was started while the app is in the background. aaronk said: Is there a way in not showing the notification ? Click to expand... No. Upvote 0
aaronk said: Without using the Service.StartForeground then it will kill the service after approx. 1 minute ? Click to expand... It will crash if the service was started while the app is in the background. aaronk said: Is there a way in not showing the notification ? Click to expand... No.