Android Question Running multiple services and keeping them alive

GuyBooth

Active Member
Licensed User
Longtime User
I have an application that runs one service with a partial lock etc to keep it running all the time.
I have another service that needs to stay alive until I turn it off.
Do I need to apply a partial lock to this service as well to make sure it stays running until I turn it off, given that the other service is holding a partial lock?

In fact do I need to apply all the following to every service, even when the first one I run is supposed to run all the time?
B4X:
Sub Process_Globals
    Private lock As PhoneWakeState
End Sub

Sub Service_Create
    lock.PartialLock
    Service.StartForeground(nid, CreateNotification("Message"))
End Sub

Sub Service_Start (StartingIntent As Intent)
    Service.StopAutomaticForeground
End Sub
 

GuyBooth

Active Member
Licensed User
Longtime User
No. A single one is enough.

It is also not needed to make your other services foreground services.
Do I always need the Service.StopAutomaticForeground? And is the Sub Service_Start the correct place to put it?
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
I have two questions:

1) Does "Service.AutomaticForegroundMode = Service.AUTOMATIC_FOREGROUND_ALWAYS" work EXACTLY the same as Service.StartForeground(nid, CreateNotification("Message")) in the context of keeping the service alive?

2) To give a service the best chance to staying alive, should either of the above lines be put in the Service_Create or Service_Start?
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…