I would like to wake up a service in 15 minute intervals and continue to do that constantly. For example, if the user pressed a button to start it and the current time is 11:05, I would like the service to wake up at 11:15, 11:30, 12:00 and so on.
I was thinking about maybe using multiple StartServiceAtExact statements but that would be a lot of them. Is there an easy way to set this up?
HI, Merry Xmas!
I couldn't test it, but IMO you should do some math in your NExtTime sub; something like:
B4X:
'TIME TO NEXT 15 minutes slot
Sub TimeToNext15 As Long
Dim minutes As Int = DateTime.GetMinute(DateTime.Now) 'ex. 09:12 --> 12
Dim gap As Int
gap = 15 - (minutes Mod 15)
Return DateTime.Now + gap * DateTime.TicksPerMinute
End Sub
....
Log(DateTime.Time(TimeToNext15)) 'ex. 09:15
Same as above, but here you pass the time to be used as the starting point for calculation as a parameter
B4X:
'TIME TO NEXT 15 minutes slot
Sub TimeToNextMinute(TimeNow As Long) As Long
Dim minutes As Int = DateTime.GetMinute(TimeNow) 'ex. 09:12 --> 12
Dim gap As Int
gap = 15 - (minutes Mod 15)
Return TimeNow + gap * DateTime.TicksPerMinute
End Sub
'call as
Log(DateTime.Time(TimeToNextMinute(DateTime.TimeParse("09:12:00")))) 'use the right time format set for your device