Determine ServiceStartAt time

surfuric

Member
Licensed User
Longtime User
How can I see if my service (which is scheduled with StartServiceAt) is in the queue and ready to run?

In my service I use a StartServiceAt, run my code, then a stopservice. I do not want the service kept alive by keeping it in the foreground. So even if I did not do a stopservice, android could destroy my service if resources get low. Which is what is happening to one of my users. Unfortunately, he has a task killer and it killed my app which also removed the service's next call from the queue. I don't care that it killed my app, but on his particular device it killed the entire app and next service queue.

So I thought it would be nice, the next time the app is started, to check to see if the Service is scheduled (not check if it is running, as it probably will not be). If it is not, give them a friendly reminder, "please make sure to exclude this app from your task killer if you want it to automatically run every hour" message.

I can easily re-schedule the service when the app starts, but I would really like to check, explain to the user what is going on, and then reschedule. I can't seem to figure out how to determine if it is in the queue. I actually have a work-around with flags and checking to see if the service ran, and more flags in a text file . . . but there has to be a better way!

Thanks,
Craig
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
There is no way to find whether your service is scheduled or not (AlarmManager doesn't give this information).

A possible (and a bit ugly) workaround can be to add another service and schedule it to run every one hour. Each time it runs it should update a file with the current time. Then when your program starts you can test when the service last ran by reading the file.
 
Upvote 0
Top