Android Question SOLVED - B4A Starting a service while app is in backgroud ? I don´t have this problem in Android 13

Antonio Ferreira

Member
Licensed User
Longtime User
Erel says "You cannot start a service while the app is in the background."

My app uses a "Main Service" that starts at boot and should run all the time (Is is a copy off Erel example "backgroud Location Tracking")
In this service I have a Timer that run every 2 minutes with startservice("service_1") , startservice("service_2") etc.
( I use this approach because Erel recomends to use StartServiceAt() with more than 30 minutes and I need 2 minutes)

Startservice("service_1) and startservice("service_2") run without problems when the app is the background (one hour in background) ?

I use B4A version 11.8
SdkVersion = 30

My phone is a Samsung 11 Ultra with Android 13
 

Antonio Ferreira

Member
Licensed User
Longtime User
If targetSdkVersion >= 31 then services cannot start at boot. You must use a receiver and it will not be able to start a service.
Only with targetSdkVersion >= 31 the services cannot start in the background. I must put my "services code" in the receiver e call the receiver with StartReceiverAt() if the receiver run time don´t exceeds 10 seconds.
This is correct ?

Thank you Erel
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0
Top