Android Question [SOLVED] What are the best strategies to handle scheduled tasks?

Xandoca

Active Member
Licensed User
Longtime User
Hi,

I'd like to know if there is a best strategy to handle scheduled tasks.
For example, schedule a service for each task, or schedule a service to run each 10 minutes or....
My objective is: build an agenda and todo app with notification.

I found the following recomendation that I think is the best.

"Each time that the service is started you should:
- Find all the tasks that were not run yet and their time has passed (or is now), and run them.
- Find the time of the next task and schedule the service with StartServiceAt.

It is possible that the service will be started while it is already running a previous task. Your code should be able to cope with this."


Thank you very much for your time and help!
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Each call to StartServiceAt resets the previous scheduled "alarms". This means that you should always schedule the closest task.

There are all kinds of ways to implement it. It depends on your requirements. Make sure to remember that the process will be killed and later created. So you cannot rely on keeping any important information in memory.
 
Upvote 0

Xandoca

Active Member
Licensed User
Longtime User
Each call to StartServiceAt resets the previous scheduled "alarms". This means that you should always schedule the closest task.

There are all kinds of ways to implement it. It depends on your requirements. Make sure to remember that the process will be killed and later created. So you cannot rely on keeping any important information in memory.
Erel,
Just checking... StartServiceAt doesn't work after a device boot, right?
I have to configure service to start at boot (#StartAtBoot: True) and then handle past tasks (during boot time) and schedule the closest task, right?

Thank you.
 
Upvote 0
Top