G Graeme Tacon Member Licensed User Longtime User May 21, 2014 #1 Hi, If you start a service with an intent using 'StartServiceAt', how do you cancel it ? See attached - clicking the 'Schedule' buttons performs 3 startserviceat, with the scheduled times 5 seconds apart. Hitting the 'Cancel' button issues a Cancelscheduledservice command and a stopservice command, but the service still fires. What have I done wrong ? Thanks Graeme Attachments servicedemo.zip servicedemo.zip 7.8 KB · Views: 262
Hi, If you start a service with an intent using 'StartServiceAt', how do you cancel it ? See attached - clicking the 'Schedule' buttons performs 3 startserviceat, with the scheduled times 5 seconds apart. Hitting the 'Cancel' button issues a Cancelscheduledservice command and a stopservice command, but the service still fires. What have I done wrong ? Thanks Graeme
Erel B4X founder Staff member Licensed User Longtime User May 21, 2014 #2 Note that each call to StartServiceAt will remove previous schedules. StartServiceAt expects a service not an intent. I've tested it with this code and it works as expected: Code: Copy Sub schedule_service(secs As Int) Dim x As Long = DateTime.Now + (secs * DateTime.TicksPerSecond) StartServiceAt(testservice, x, True) End Sub Upvote 0
Note that each call to StartServiceAt will remove previous schedules. StartServiceAt expects a service not an intent. I've tested it with this code and it works as expected: Code: Copy Sub schedule_service(secs As Int) Dim x As Long = DateTime.Now + (secs * DateTime.TicksPerSecond) StartServiceAt(testservice, x, True) End Sub
G Graeme Tacon Member Licensed User Longtime User May 21, 2014 #3 Thanks for the reply Erel What I was trying to do in my app was just have 1 service which had multiple functions, rather than have several small services. By using startserviceat with an intent (which I'd picked up on another post), I could achieve that, especially as you can do multiple calls which don't remove previous schedules. The issue is that I don't know how you can remove one that has been scheduled before it reaches the scheduled time. I guess I will have to revert to having multiple services. Upvote 0
Thanks for the reply Erel What I was trying to do in my app was just have 1 service which had multiple functions, rather than have several small services. By using startserviceat with an intent (which I'd picked up on another post), I could achieve that, especially as you can do multiple calls which don't remove previous schedules. The issue is that I don't know how you can remove one that has been scheduled before it reaches the scheduled time. I guess I will have to revert to having multiple services.
Erel B4X founder Staff member Licensed User Longtime User May 22, 2014 #4 Another option is to schedule the next "alarm" each time. You can store a list with all the scheduled times and then schedule the next one each time. Upvote 0
Another option is to schedule the next "alarm" each time. You can store a list with all the scheduled times and then schedule the next one each time.