How to setup a service?

Mark Read

Well-Known Member
Licensed User
Longtime User
I have created an activity which sets two times: TimeOn and TimeOff, -these are global variables stored as Long. Example data would be (24H clock)

TimeOn=22:00
TimeOff=06:00

I want to pass these two values to a service which runs all the time. It should check the current time and if it is later than TImeOn, then turn on FlightMode and if later than TimeOff (the next morning), turn it back off again. This should happen every day.

Questions:
1. How do I check the time? Using DateUtils?
2. Should my global variables be in the service?

Any help would be great. Many thanks.
Mark
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You do not need to create a service that runs all the time. You should instead use StartServiceAt.

There are several ways to accomplish it. I recommend you to create two services and then schedule both of them. Every important information should be saved in a file as the process will be killed and later recreated.
 
Upvote 0

Mark Read

Well-Known Member
Licensed User
Longtime User
Thanks Erel,

so if I understand correctly:

1. I create a service to start at "TimeOn" which turns on flight mode and schedules service 2.
2. Service 2 starts at "TimeOff" which turns mode off.
3. The first service runs until the second service starts, which in turn stops the first. The second service can then schedule the first again.
4. The 2 variables TimeOn and TimeOff need to be stored in a file.

Hope I have explained that correctly.
Regards
Mark
 
Last edited:
Upvote 0
Top