Android Question App with 2 services

Alessandro71

Well-Known Member
Licensed User
Longtime User
My app has 2 services (actually 3, if you count the starter also)
The first service is running in the foreground, with a notification displayed.
This should assure it won’t get killed under SDK 26 rules.
The second service is running alongside the first, it is actually started in Service_Start of the first one, and should have the same lifecycle of the first, i.e. always running.
Does having the first service running in foreground, also shields the second one from being killed by the OS, or should I start also the second one in foreground, displaying a second notification icon, that will be redundant and may confuse the user?
 

Alessandro71

Well-Known Member
Licensed User
Longtime User
Nice question: for code clarity, I preferred to implement 2 different functionalities in 2 different services.
Each one has different timers and events.
The second service is also an optional functionality, so it may not be started at all, if not required.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Does having the first service running in foreground, also shields the second one from being killed by the OS, or should I start also the second one in foreground, displaying a second notification icon, that will be redundant and may confuse the user?
Yes. The OS will not kill any service while your app is in the foreground state. Having a single foreground service is enough for your app to be in the foreground state.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…