Reading this topic about Calculating the next scheduled time:
The code from above link:
How can I incorporate this into a Service where I can use CallSubDelayed to trigger an event in Activity Main when one of the three times are met?
The code from above link:
B4X:
Dim t As Long = FindNextTime(Array As Double(5, 6.5, 20))
Log($"Next time is: $DateTime{t}"$)
Sub FindNextTime(Times As List) As Long
Times.Sort(True)
For Each st As Double In Times
If SetHours(st) > DateTime.Now Then
Return SetHours(st)
End If
Next
Return DateTime.Add(SetHours(Times.Get(0)), 0, 0, 1)
End Sub
Sub SetHours(st As Double) As Long
Dim hours As Int = Floor(st)
Dim minutes As Int = 60 * (st - hours)
Return DateUtils.SetDateAndTime(DateTime.GetYear(DateTime.Now), _
DateTime.GetMonth(DateTime.Now), DateTime.GetDayOfMonth(DateTime.Now), hours, minutes, 0)
End Sub