Android Question StartServiceAt and StopService

Marcos Alves

Well-Known Member
Licensed User
Longtime User
Hello,

I have a doubt. I'm scheduling a service to start every 30 seconds, but I don't need the service running between the intervals... then, I use the code...


B4X:
Sub Service_Start (StartingIntent As Intent)
      do everything...
     StartServiceAt("",DateTime.Now + 30000,True)
    StopService("")
End Sub

Of course that if I check between the intervals if the service is running (using IsPaused(service)) then I'll have true (for pause). But how can I know if the service is scheduled? And if I start again, even if scheduled, I'll have two scheduled instances or the system will respect the last call and cancel any scheduled time for the service?
 

Peter Simpson

Expert
Licensed User
Longtime User
Last edited:
Upvote 0

Marcos Alves

Well-Known Member
Licensed User
Longtime User
I done a workaround: always before startservice I use CancelScheduledService. Then I know that there is no risk to have two instances running. I think that this approach will always work, doesn't it?
 
Last edited:
Upvote 0
Top