service.starforeground

marcick

Well-Known Member
Licensed User
Longtime User
HI all,
I have a service that intercept incoming SMS and I use

B4X:
Service.StartForeground

to prevent the service is killed form the OS.

So the service run forever, but happens (rarely but happens) that it is killed again.

I'm thinking to use
B4X:
StartServiceAt("", DateTime.Now + 60 * DateTime.TicksPerSecond, True)

But to be really useful I would need to specify a very short time of 10 seconds or less.

I wonder if this could have some negative effects (resources, power consumption, I don't know).

Also, what happens when the scheduled event raisebut the service is already running ? Is the code in service_start executed again ? (and how eventually to avoid it) ?

Marco
 

marcick

Well-Known Member
Licensed User
Longtime User
Yes Erel, but I didn't consider it because I need to capture SMS and decide if pass them or not to the SMS manager. If I have read well, this is not possible with static receiver.
Marco
 
Upvote 0

djpero

Member
Licensed User
Longtime User
You can use in combination:

* SMS_RECEIVE intent to start service
* SMS intercept lib to decide what with sms
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
If I have read well, this is not possible with static receiver.
You are correct.


Your code will work though it will affect battery consumption.
Also, what happens when the scheduled event raisebut the service is already running ? Is the code in service_start executed again ? (and how eventually to avoid it) ?
Service_Start will be called again.
Move all the code to Service_Create (except of StartServiceAt).
 
Upvote 0
Top