Android Question Ideal Background Service Setup


Active Member
Licensed User
I am using B4XPages in my project.
There is a TTS module which is supposed to play even when screen is turned off.
It plays for a while then pauses and resumes only when screen is unlocked ( probably as long as tts queue is clear)
So after a lot of forum search - using a service seems to be the way to go
However I have a few questions, if experts here can help me with.

1. Will the service work with TTS the same way it does for playing audio ?
2. Do we move code for TTS play to service or just a new sub which keeps calling B4Xpages methods?
3. If service is started as Service.startForeground, How do we know when service actually resumes to foreground (phone unlocked/screen unlocked and app gets focus)
4. Do we destroy service every time the task is complete or only call service.StopForeground