Android Question android.app.RemoteServiceException: Context.startForegroundService() did not then call Service.startForeground(): ServiceRecord

petr4ppc

Well-Known Member
Licensed User
Longtime User
Dear friends, please,

I am fighting with situation which is for me confused.
But I must try to ask you.
I am playing with VOSK offline speech to text and if I have my phone locked (it does it mean display is OFF),
then I get after short time this:
Context.startForegroundService() did not then call Service.startForeground(): ServiceRecord
before I put here code (I must edit the code for easy interpretation here) I want ask,
if this error is because of Android. I mean - if Android kill the STT recognition or if the mistake is in my code.

If I run the app with mobile phone which is active (display ON), then I dont get this this error.

I am using in servicestart and servicecreate:
B4X:
Service.AutomaticForegroundMode = Service.AUTOMATIC_FOREGROUND_NEVER
lock.PartialLock

Please, is somebody who have same behavior or can somebody give me some advice, please,
p4ppc
 

DonManfred

Expert
Licensed User
Longtime User
servicestart
you need to have the drawoverotherapps permission when you want to start a service while in background.
Did you add it?

You must have the special "draw over apps" permissions to start activities from the background on Android 10+.

Not sure if this is needed here: you are giving not enough informations.
 
Upvote 0

petr4ppc

Well-Known Member
Licensed User
Longtime User
Dear DonManfred,

thank you very much for your answer.


I see the list of drawoverotherapps, but I dont see my app here I think I must declare it in code too...please how can I do it?

Best regards
p4ppc
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Why have you set the automatic mode to NEVER? This will cause your app to crash if the service is started while the app is in the background.
 
Upvote 0

petr4ppc

Well-Known Member
Licensed User
Longtime User
Dear Mr. Erel,

the reason why I am not writing answer is, because I am still finding solutions and my mistakes.
I have changed automatic mode from NEVER to ALWAYS and after 24hours (maybe 48hours) of testing it looks that the message

android.app.RemoteServiceException: Context.startForegroundService() did not then call Service.startForeground(): ServiceRecord

was not born. I hope that its true, I will write soon with final result.
Thank you very much and best regards
p4ppc
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…